Skip to content

Commit fe2238f

Browse files
committed
refactor: remove isAnonymous from User model
- Simplify user representation - Remove unused field
1 parent 3613d43 commit fe2238f

File tree

4 files changed

+23
-42
lines changed

4 files changed

+23
-42
lines changed

lib/src/models/user.dart

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ part 'user.g.dart';
1313
class User extends Equatable {
1414
/// Creates a new [User] instance.
1515
///
16-
/// Requires a unique [id], an [isAnonymous] flag, and a [role].
17-
/// The [email] is optional and typically present only for non-anonymous
18-
/// users who have verified their email address.
16+
/// Requires a unique [id] and a [role].
17+
/// The [email] is optional and typically present only for users
18+
/// who have verified their email address.
1919
const User({
2020
required this.id,
21-
required this.isAnonymous,
2221
required this.role,
2322
this.email,
2423
});
@@ -31,27 +30,20 @@ class User extends Equatable {
3130

3231
/// The user's email address.
3332
///
34-
/// This will be `null` for anonymous users or users who haven't
35-
/// associated an email yet.
33+
/// This will be `null` for users who haven't associated an email yet.
3634
final String? email;
3735

38-
/// Indicates whether the user is authenticated anonymously.
39-
///
40-
/// `true` if the user signed in using the anonymous flow,
41-
/// `false` otherwise.
42-
final bool isAnonymous;
43-
44-
/// The role of the user (e.g., 'admin', 'standard_user').
36+
/// The role of the user (e.g., 'admin', 'standard_user', 'guest_user').
4537
final String role;
4638

4739
/// Converts this User instance to JSON data.
4840
Map<String, dynamic> toJson() => _$UserToJson(this);
4941

5042
@override
51-
List<Object?> get props => [id, email, isAnonymous, role];
43+
List<Object?> get props => [id, email, role];
5244

5345
@override
5446
String toString() {
55-
return 'User(id: $id, email: $email, isAnonymous: $isAnonymous, role: $role)';
47+
return 'User(id: $id, email: $email, role: $role)';
5648
}
5749
}

lib/src/models/user.g.dart

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/src/models/auth_success_response_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ void main() {
77
const testUser = User(
88
id: 'user-123',
99
email: 'test@example.com',
10-
isAnonymous: false,
1110
role: 'standard_user',
1211
);
1312
const testToken = 'sample-jwt-token';
@@ -95,8 +94,7 @@ void main() {
9594
const updatedUser = User(
9695
id: 'user-456',
9796
email: 'updated@example.com',
98-
isAnonymous: true,
99-
role: 'standard_user',
97+
role: 'guest_user',
10098
);
10199
final copiedResponse = authSuccessResponse.copyWith(user: updatedUser);
102100

@@ -119,8 +117,7 @@ void main() {
119117
test('should create a copy with both user and token updated', () {
120118
const updatedUser = User(
121119
id: 'user-789',
122-
isAnonymous: true,
123-
role: 'standard_user',
120+
role: 'guest_user',
124121
);
125122
const updatedToken = 'another-token-xyz';
126123
final copiedResponse = authSuccessResponse.copyWith(
@@ -145,7 +142,6 @@ void main() {
145142
test('should not equate instances with different users', () {
146143
const differentUser = User(
147144
id: 'diff-user',
148-
isAnonymous: false,
149145
role: 'admin',
150146
);
151147
const response1 = AuthSuccessResponse(user: testUser, token: testToken);

test/src/models/user_test.dart

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,48 @@ void main() {
88

99
test('supports value equality', () {
1010
expect(
11-
const User(id: id, email: email, isAnonymous: false, role: 'standard_user'),
11+
const User(id: id, email: email, role: 'standard_user'),
1212
equals(
13-
const User(id: id, email: email, isAnonymous: false, role: 'standard_user'),
13+
const User(id: id, email: email, role: 'standard_user'),
1414
),
1515
);
1616
expect(
17-
const User(id: id, email: email, isAnonymous: false, role: 'standard_user'),
17+
const User(id: id, email: email, role: 'standard_user'),
1818
isNot(
1919
equals(
2020
const User(
2121
id: 'other-id',
2222
email: email,
23-
isAnonymous: false,
2423
role: 'standard_user',
2524
),
2625
),
2726
),
2827
);
2928
expect(
30-
const User(id: id, email: email, isAnonymous: false, role: 'standard_user'),
29+
const User(id: id, email: email, role: 'standard_user'),
3130
isNot(
3231
equals(
3332
const User(
3433
id: id,
3534
email: 'other@example.com',
36-
isAnonymous: false,
3735
role: 'standard_user',
3836
),
3937
),
4038
),
4139
);
4240
expect(
43-
const User(id: id, email: email, isAnonymous: false, role: 'standard_user'),
41+
const User(id: id, email: email, role: 'standard_user'),
4442
isNot(
4543
equals(
46-
const User(id: id, email: email, isAnonymous: true, role: 'standard_user'),
44+
const User(id: id, email: email, role: 'guest_user'),
4745
),
4846
),
4947
);
5048
expect(
51-
const User(id: id, email: email, isAnonymous: false, role: 'standard_user'),
49+
const User(id: id, email: email, role: 'standard_user'),
5250
isNot(
5351
equals(
54-
const User(id: id, email: email, isAnonymous: false, role: 'admin'),
52+
const User(id: id, email: email, role: 'admin'),
5553
),
5654
),
5755
);
@@ -62,20 +60,19 @@ void main() {
6260
const User(
6361
id: id,
6462
email: email,
65-
isAnonymous: false,
6663
role: 'standard_user',
6764
).toString(),
6865
equals(
69-
'User(id: $id, email: $email, isAnonymous: false, role: standard_user)',
66+
'User(id: $id, email: $email, role: standard_user)',
7067
),
7168
);
7269
expect(
73-
const User(id: id, isAnonymous: true, role: 'standard_user').toString(),
74-
equals('User(id: $id, email: null, isAnonymous: true, role: standard_user)'),
70+
const User(id: id, role: 'guest_user').toString(),
71+
equals('User(id: $id, email: null, role: guest_user)'),
7572
);
7673
expect(
77-
const User(id: id, isAnonymous: false, role: 'admin').toString(),
78-
equals('User(id: $id, email: null, isAnonymous: false, role: admin)'),
74+
const User(id: id, role: 'admin').toString(),
75+
equals('User(id: $id, email: null, role: admin)'),
7976
);
8077
});
8178

@@ -84,22 +81,20 @@ void main() {
8481
const user = User(
8582
id: id,
8683
email: email,
87-
isAnonymous: false,
8884
role: 'standard_user',
8985
);
9086
final json = user.toJson();
9187
final deserializedUser = User.fromJson(json);
9288
expect(deserializedUser, equals(user));
9389

94-
const anonUser = User(id: id, isAnonymous: true, role: 'standard_user');
90+
const anonUser = User(id: id, role: 'guest_user');
9591
final anonJson = anonUser.toJson();
9692
final deserializedAnonUser = User.fromJson(anonJson);
9793
expect(deserializedAnonUser, equals(anonUser));
9894

9995
const adminUser = User(
10096
id: id,
10197
email: email,
102-
isAnonymous: false,
10398
role: 'admin',
10499
);
105100
final adminJson = adminUser.toJson();

0 commit comments

Comments
 (0)