Skip to content

Commit d2d656e

Browse files
committed
refactor(login): move userInfo retrieval outside conditional blocks
Simplify the login command logic by retrieving userInfo once at the beginning of the method. This reduces redundancy and improves code readability.
1 parent 59406fa commit d2d656e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/src/command/login.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,28 @@ class LoginCommand extends PubCommand {
2424
@override
2525
Future<void> runProtected() async {
2626
final credentials = oauth2.loadCredentials();
27+
final userInfo = await _retrieveUserInfo();
28+
2729
if (credentials == null) {
28-
final userInfo = await _retrieveUserInfo();
2930
if (userInfo == null) {
3031
log.warning(
31-
'Could not retrieve your user-details.\n'
32-
'You might have to run `$topLevelProgram pub logout` '
33-
'to delete your credentials and try again.',
32+
'Could not retrieve your user details.\n'
33+
'Run `$topLevelProgram pub logout` to delete credentials and try '
34+
'again.',
3435
);
3536
} else {
3637
log.message('You are now logged in as $userInfo');
3738
}
3839
} else {
39-
final userInfo = await _retrieveUserInfo();
4040
if (userInfo == null) {
4141
log.warning(
42-
'Your credentials seems broken.\n'
43-
'Run `$topLevelProgram pub logout` '
44-
'to delete your credentials and try again.',
42+
'Your credentials seem to be broken.\n'
43+
'Run `$topLevelProgram pub logout` to delete credentials and try '
44+
'again.',
4545
);
46+
} else {
47+
log.message('You are already logged in as $userInfo');
4648
}
47-
log.warning(
48-
'You are already logged in as $userInfo\n'
49-
'Run `$topLevelProgram pub logout` to log out and try again.',
50-
);
5149
}
5250
}
5351

0 commit comments

Comments
 (0)