16 lines
498 B
Dart
16 lines
498 B
Dart
import 'dart:io';
|
|
|
|
import 'package:dart_frog/dart_frog.dart';
|
|
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
|
|
|
final String jwtSecret = Platform.environment['JWT_SECRET'] ?? 'googoogaga-key';
|
|
|
|
extension RequestContextX on RequestContext {
|
|
String get userId {
|
|
final authHeader = request.headers['authorization'] ?? '';
|
|
final token = authHeader.replaceAll('Bearer ', '');
|
|
final jwt = JWT.verify(token, SecretKey(jwtSecret));
|
|
return jwt.payload['userId'] as String;
|
|
}
|
|
}
|