@@ -169,9 +169,21 @@ class AuthService {
169
169
170
170
// All new users created via the public API get the standard role.
171
171
// Admin users must be provisioned out-of-band (e.g., via fixtures).
172
- final roles = [UserRoles .standardUser];
173
-
174
- user = User (id: _uuid.v4 (), email: email, roles: roles);
172
+ user = User (
173
+ id: _uuid.v4 (),
174
+ email: email,
175
+ appRole: AppUserRole .standardUser,
176
+ dashboardRole: DashboardUserRole .none,
177
+ createdAt: DateTime .now (),
178
+ feedActionStatus: Map .fromEntries (
179
+ FeedActionType .values.map (
180
+ (type) => MapEntry (
181
+ type,
182
+ const UserFeedActionStatus (isCompleted: false ),
183
+ ),
184
+ ),
185
+ ),
186
+ );
175
187
user = await _userRepository.create (item: user);
176
188
print ('Created new user: ${user .id } with roles: ${user .roles }' );
177
189
@@ -224,9 +236,21 @@ class AuthService {
224
236
User user;
225
237
try {
226
238
user = User (
227
- id: _uuid.v4 (), // Generate new ID
228
- roles: const [UserRoles .guestUser], // Anonymous users are guest users
229
- email: null , // Anonymous users don't have an email initially
239
+ id: _uuid.v4 (),
240
+ // Use a unique placeholder email for anonymous users to satisfy the
241
+ // non-nullable email constraint.
242
+ email: '${_uuid .v4 ()}@anonymous.com' ,
243
+ appRole: AppUserRole .guestUser,
244
+ dashboardRole: DashboardUserRole .none,
245
+ createdAt: DateTime .now (),
246
+ feedActionStatus: Map .fromEntries (
247
+ FeedActionType .values.map (
248
+ (type) => MapEntry (
249
+ type,
250
+ const UserFeedActionStatus (isCompleted: false ),
251
+ ),
252
+ ),
253
+ ),
230
254
);
231
255
user = await _userRepository.create (item: user);
232
256
print ('Created anonymous user: ${user .id }' );
@@ -335,7 +359,7 @@ class AuthService {
335
359
required User anonymousUser,
336
360
required String emailToLink,
337
361
}) async {
338
- if (! anonymousUser.roles. contains ( UserRoles . guestUser) ) {
362
+ if (anonymousUser.appRole != AppUserRole . guestUser) {
339
363
throw const BadRequestException (
340
364
'Account is already permanent. Cannot link email.' ,
341
365
);
@@ -348,8 +372,7 @@ class AuthService {
348
372
349
373
// Filter for permanent users (not guests) that are not the current user.
350
374
final conflictingPermanentUsers = existingUsersResponse.items.where (
351
- (u) =>
352
- ! u.roles.contains (UserRoles .guestUser) && u.id != anonymousUser.id,
375
+ (u) => u.appRole != AppUserRole .guestUser && u.id != anonymousUser.id,
353
376
);
354
377
355
378
if (conflictingPermanentUsers.isNotEmpty) {
@@ -399,7 +422,7 @@ class AuthService {
399
422
required String codeFromUser,
400
423
required String oldAnonymousToken, // Needed to invalidate it
401
424
}) async {
402
- if (! anonymousUser.roles. contains ( UserRoles . guestUser) ) {
425
+ if (anonymousUser.appRole != AppUserRole . guestUser) {
403
426
// Should ideally not happen if flow is correct, but good safeguard.
404
427
throw const BadRequestException (
405
428
'Account is already permanent. Cannot complete email linking.' ,
@@ -421,10 +444,9 @@ class AuthService {
421
444
}
422
445
423
446
// 2. Update the user to be permanent.
424
- final updatedUser = User (
425
- id: anonymousUser.id, // Preserve original ID
447
+ final updatedUser = anonymousUser.copyWith (
426
448
email: linkedEmail,
427
- roles : const [ UserRoles .standardUser], // Now a permanent standard user
449
+ appRole : AppUserRole .standardUser,
428
450
);
429
451
final permanentUser = await _userRepository.update (
430
452
id: updatedUser.id,
0 commit comments