Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update auth-google.mdx (#36780)

David10cc742349ea
diff --git a/apps/docs/content/guides/auth/social-login/auth-google.mdx b/apps/docs/content/guides/auth/social-login/auth-google.mdx
index 520fb9a3a00..e73d62e6cf0 100644
--- a/apps/docs/content/guides/auth/social-login/auth-google.mdx
+++ b/apps/docs/content/guides/auth/social-login/auth-google.mdx
@@ -540,26 +540,37 @@ Future<void> _nativeGoogleSignIn() async {
/// iOS Client ID that you registered with Google Cloud.
const iosClientId = 'my-ios.apps.googleusercontent.com';
- final GoogleSignIn googleSignIn = GoogleSignIn(
- clientId: iosClientId,
+ final scopes = ['email', 'profile'];
+ final googleSignIn = GoogleSignIn.instance;
+
+ await googleSignIn.initialize(
serverClientId: webClientId,
+ clientId: iosClientId,
);
- final googleUser = await googleSignIn.signIn();
- final googleAuth = await googleUser!.authentication;
- final accessToken = googleAuth.accessToken;
- final idToken = googleAuth.idToken;
- if (accessToken == null) {
- throw 'No Access Token found.';
+ final googleUser = await googleSignIn.attemptLightweightAuthentication();
+ // or await googleSignIn.authenticate(); which will return a GoogleSignInAccount or throw an exception
+
+ if (googleUser == null) {
+ throw AuthException('Failed to sign in with Google.');
}
+
+ /// Authorization is required to obtain the access token with the appropriate scopes for Supabase authentication,
+ /// while also granting permission to access user information.
+ final authorization =
+ await googleUser.authorizationClient.authorizationForScopes(scopes) ??
+ await googleUser.authorizationClient.authorizeScopes(scopes);
+
+ final idToken = googleUser.authentication.idToken;
+
if (idToken == null) {
- throw 'No ID Token found.';
+ throw AuthException('No ID Token found.');
}
await supabase.auth.signInWithIdToken(
provider: OAuthProvider.google,
idToken: idToken,
- accessToken: accessToken,
+ accessToken: authorization.accessToken,
);
}
...