Skip to content

Commit 4e4fc04

Browse files
committed
refactor(auth): replace UUID with MongoDB ObjectId for JWT ID
- Remove Uuid dependency and replace it with mongo_dart ObjectId - Update JWT claims to use ObjectId.oid for 'jti' (JWT ID) - Adjust constructor to remove Uuid parameter - Update import statements to reflect changes
1 parent d7e24c8 commit 4e4fc04

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/src/services/jwt_auth_token_service.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
22
import 'package:ht_api/src/services/auth_token_service.dart';
3+
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
4+
import 'package:ht_api/src/services/auth_token_service.dart';
35
import 'package:ht_api/src/services/token_blacklist_service.dart';
46
import 'package:ht_data_repository/ht_data_repository.dart';
57
import 'package:ht_shared/ht_shared.dart';
68
import 'package:logging/logging.dart';
7-
import 'package:uuid/uuid.dart';
9+
import 'package:mongo_dart/mongo_dart.dart';
810

911
/// {@template jwt_auth_token_service}
1012
/// An implementation of [AuthTokenService] using JSON Web Tokens (JWT).
@@ -19,20 +21,16 @@ class JwtAuthTokenService implements AuthTokenService {
1921
/// - [userRepository]: To fetch user details after validating the token's
2022
/// subject claim.
2123
/// - [blacklistService]: To manage the blacklist of invalidated tokens.
22-
/// - [uuidGenerator]: For creating unique JWT IDs (jti).
2324
const JwtAuthTokenService({
2425
required HtDataRepository<User> userRepository,
2526
required TokenBlacklistService blacklistService,
26-
required Uuid uuidGenerator,
2727
required Logger log,
2828
}) : _userRepository = userRepository,
2929
_blacklistService = blacklistService,
30-
_uuid = uuidGenerator,
3130
_log = log;
3231

3332
final HtDataRepository<User> _userRepository;
3433
final TokenBlacklistService _blacklistService;
35-
final Uuid _uuid;
3634
final Logger _log;
3735

3836
// --- Configuration ---
@@ -61,7 +59,7 @@ class JwtAuthTokenService implements AuthTokenService {
6159
'exp': expiry.millisecondsSinceEpoch ~/ 1000, // Expiration Time
6260
'iat': now.millisecondsSinceEpoch ~/ 1000, // Issued At
6361
'iss': _issuer, // Issuer
64-
'jti': _uuid.v4(), // JWT ID (for potential blacklisting)
62+
'jti': ObjectId().oid, // JWT ID (for potential blacklisting)
6563
// Custom claims (optional, include what's useful)
6664
'email': user.email, // Kept for convenience
6765
// Embed the new enum-based roles. Use .name for string value.
@@ -70,7 +68,7 @@ class JwtAuthTokenService implements AuthTokenService {
7068
},
7169
issuer: _issuer,
7270
subject: user.id,
73-
jwtId: _uuid.v4(), // Re-setting jti here for clarity if needed
71+
jwtId: ObjectId().oid, // Re-setting jti here for clarity if needed
7472
);
7573

7674
// Sign the token using HMAC-SHA256

0 commit comments

Comments
 (0)