Skip to content

Commit 7d099bb

Browse files
committed
resolved codefu comments
1 parent 982f975 commit 7d099bb

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

dashboard/lib/service/firebase_auth.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,19 @@ class FirebaseAuthService extends ChangeNotifier {
7777
try {
7878
final userCredential = await _auth.signInWithPopup(GithubAuthProvider());
7979
_user = userCredential.user;
80-
} catch (error) {
80+
} on FirebaseAuthException catch (error) {
8181
// If email of Github account already registered in Frebase but with
8282
// Google provider, we need to sign in with Google provider first,
8383
// then link the GitHub provider to Google provider.
84-
if (error is FirebaseAuthException &&
85-
error.code == 'account-exists-with-different-credential') {
84+
if (error.code == 'account-exists-with-different-credential') {
8685
debugPrint('google account exists, signing in with google');
8786
await _signInWithGoogle();
8887
await _linkWithGithub();
8988
return;
9089
}
9190
debugPrint('signin with github failed: $error');
91+
} catch (error) {
92+
debugPrint('signin with github failed: $error');
9293
}
9394
}
9495

@@ -125,16 +126,16 @@ class FirebaseAuthService extends ChangeNotifier {
125126
_user = userCredential?.user;
126127
notifyListeners();
127128
await _auth.currentUser?.getIdToken(true);
128-
} catch (error) {
129-
// If Google account's credential already exists in firebase, we going to
130-
// link github account to google.
131-
if (error is FirebaseAuthException &&
132-
error.code == 'credential-already-in-use') {
129+
} on FirebaseAuthException catch (error) {
130+
// If Github account's credential already exists in firebase, we going to
131+
// link google account to github.
132+
if (error.code == 'credential-already-in-use') {
133133
await _relinkGithubToGoogle();
134134
return;
135135
}
136136
debugPrint('linkWithGoogle failed: $error');
137-
//
137+
} catch (error) {
138+
debugPrint('linkWithGoogle failed: $error');
138139
}
139140
// If linking google succeeded, we need to unlink it and relink
140141
// github to google to make google primary.

dashboard/lib/widgets/user_sign_in.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,13 @@ class UserSignIn extends StatelessWidget {
167167
}
168168

169169
extension on String {
170-
String getUserInitials() {
171-
// Define the regular expression to split by space, dots,underscore, or dash
172-
final splitter = RegExp(r'[ ._-]+');
170+
static final RegExp _splitter = RegExp(r'[ ._-]+');
173171

172+
String getUserInitials() {
174173
final parts =
175174
split('@') // Split the email into local and domain parts
176175
.first // Take only the local part (before the '@' symbol)
177-
.split(splitter); // Split string into a list of substrings
176+
.split(_splitter); // Split string into a list of substrings
178177

179178
// Extract the first character of each non-empty part and join them.
180179
final result = parts

dashboard/test/utils/fake_firebase_user.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FakeFirebaseUser implements User {
1010
throw UnimplementedError();
1111
}
1212

13-
final _tokens = <String>[];
13+
final tokens = <String>[];
1414
final _providerData = <UserInfo>[];
1515

1616
@override
@@ -24,8 +24,8 @@ class FakeFirebaseUser implements User {
2424

2525
@override
2626
Future<String?> getIdToken([bool forceRefresh = false]) async {
27-
if (_tokens.isEmpty) return null;
28-
return _tokens.removeAt(0);
27+
if (tokens.isEmpty) return null;
28+
return tokens.removeAt(0);
2929
}
3030

3131
@override

0 commit comments

Comments
 (0)