Skip to content

Commit 37af313

Browse files
committed
fix(auth): add isAdmin field to User model
- Added isAdmin field to User - Set default isAdmin value to false
1 parent 9de9ebb commit 37af313

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/src/services/auth_service.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class AuthService {
116116
id: _uuid.v4(), // Generate new ID
117117
email: email,
118118
isAnonymous: false, // Email verified user is not anonymous
119+
isAdmin: false,
119120
);
120121
user = await _userRepository.create(item: user); // Save the new user
121122
print('Created new user: ${user.id}');
@@ -156,6 +157,7 @@ class AuthService {
156157
id: _uuid.v4(), // Generate new ID
157158
isAnonymous: true,
158159
email: null, // Anonymous users don't have an email initially
160+
isAdmin: false,
159161
);
160162
user = await _userRepository.create(item: user);
161163
print('Created anonymous user: ${user.id}');
@@ -214,14 +216,14 @@ class AuthService {
214216
// Invalidate the token using the AuthTokenService
215217
await _authTokenService.invalidateToken(token);
216218
print(
217-
'[AuthService] Token invalidation logic executed for user $userId.');
219+
'[AuthService] Token invalidation logic executed for user $userId.',);
218220
} on HtHttpException catch (_) {
219221
// Propagate known exceptions from the token service
220222
rethrow;
221223
} catch (e) {
222224
// Catch unexpected errors during token invalidation
223225
print(
224-
'[AuthService] Error during token invalidation for user $userId: $e');
226+
'[AuthService] Error during token invalidation for user $userId: $e',);
225227
throw const OperationFailedException(
226228
'Failed server-side sign-out: Token invalidation failed.',
227229
);
@@ -332,6 +334,7 @@ class AuthService {
332334
id: anonymousUser.id, // Preserve original ID
333335
email: linkedEmail,
334336
isAnonymous: false, // Now a permanent user
337+
isAdmin: false,
335338
);
336339
final permanentUser = await _userRepository.update(
337340
id: updatedUser.id,

test/src/services/jwt_auth_token_service_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ void main() {
2222
id: 'user-jwt-123',
2323
2424
isAnonymous: false,
25+
isAdmin: false,
2526
);
2627
const testUuidValue = 'test-uuid-v4';
2728

2829
setUpAll(() {
2930
// Register fallback values for argument matchers
30-
registerFallbackValue(const User(id: 'fallback', isAnonymous: true));
31+
registerFallbackValue(
32+
const User(id: 'fallback', isAnonymous: true, isAdmin: false),);
3133
// Register fallback for DateTime if needed for blacklist mock
3234
registerFallbackValue(DateTime(2024));
3335
});

0 commit comments

Comments
 (0)