Skip to content

Commit

Permalink
Fix disconnecting Google account for signing in with Google. (#1341)
Browse files Browse the repository at this point in the history
Tested it locally 👍 When a user never signed in with Google, the
`disconnect` method will throw an exception.

Fixes #1339
  • Loading branch information
nilsreichardt authored Mar 1, 2024
1 parent 7330707 commit acfbb3f
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ class GoogleSignInLogic {
}

Future<AuthCredential> _getCredentials() async {
// Disconnect the user before signing in again to ensure that the user can
// select other Google accounts.
//
// Otherwise, the user would be signed in with the last selected account
// without the possibility to select another Google account. This is a
// problem when the user wasn't sure which Google account was the right one,
// signs in with the wrong account, and then wants to sign in with the
// correct account. Especially on Android is this a problem.
//
// From: https://stackoverflow.com/a/58509980/8358501
await _googleSignIn.disconnect();
try {
// Disconnect the user before signing in again to ensure that the user can
// select other Google accounts.
//
// Otherwise, the user would be signed in with the last selected account
// without the possibility to select another Google account. This is a
// problem when the user wasn't sure which Google account was the right one,
// signs in with the wrong account, and then wants to sign in with the
// correct account. Especially on Android is this a problem.
//
// From: https://stackoverflow.com/a/58509980/8358501
await _googleSignIn.disconnect();
} catch (e) {
// Ignore the error because the user might not have selected an account
// yet. In this case, the error is expected.
}

final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser == null) throw NoGoogleSignAccountSelected();
Expand Down

0 comments on commit acfbb3f

Please sign in to comment.