Skip to content

Commit 578a2d9

Browse files
committed
refactor(api): update JwtAuthTokenService to use roles list in payload
1 parent 25c873a commit 578a2d9

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

lib/src/services/jwt_auth_token_service.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import 'package:ht_data_repository/ht_data_repository.dart';
55
import 'package:ht_shared/ht_shared.dart';
66
import 'package:uuid/uuid.dart';
77

8-
/// Helper function to convert UserRole enum to its snake_case string.
9-
String _userRoleToString(UserRole role) {
10-
return switch (role) {
11-
UserRole.admin => 'admin',
12-
UserRole.standardUser => 'standard_user',
13-
UserRole.guestUser => 'guest_user',
14-
UserRole.premiumUser => 'premium_user',
15-
};
16-
}
17-
188
/// {@template jwt_auth_token_service}
199
/// An implementation of [AuthTokenService] using JSON Web Tokens (JWT).
2010
///
@@ -70,9 +60,7 @@ class JwtAuthTokenService implements AuthTokenService {
7060
'jti': _uuid.v4(), // JWT ID (for potential blacklisting)
7161
// Custom claims (optional, include what's useful)
7262
'email': user.email,
73-
'role': _userRoleToString(
74-
user.role,
75-
), // Include the user's role as a string
63+
'roles': user.roles, // Include the user's roles as a list of strings
7664
},
7765
issuer: _issuer,
7866
subject: user.id,

0 commit comments

Comments
 (0)