@@ -136,6 +136,8 @@ Once you have registered your app and created the client IDs, add the web client
136
136
137
137
At this point you can perform native Google sign in using the following code. Be sure to replace the ` webClientId ` and ` iosClientId ` with your own.
138
138
139
+ The following example is very basic. Please refer to the [ google_sign_in] ( https://pub.dev/packages/google_sign_in ) package for the correct details.
140
+
139
141
``` dart
140
142
import 'package:google_sign_in/google_sign_in.dart';
141
143
import 'package:supabase_flutter/supabase_flutter.dart';
@@ -156,18 +158,19 @@ Future<AuthResponse> _googleSignIn() async {
156
158
// Google sign in on Android will work without providing the Android
157
159
// Client ID registered on Google Cloud.
158
160
159
- final GoogleSignIn googleSignIn = GoogleSignIn(
160
- clientId: iosClientId,
161
- serverClientId: webClientId,
162
- );
163
- final googleUser = await googleSignIn.signIn();
164
- final googleAuth = await googleUser!.authentication;
165
- final accessToken = googleAuth.accessToken;
166
- final idToken = googleAuth.idToken;
161
+ final GoogleSignIn signIn = GoogleSignIn.instance;
162
+
163
+ // At the start of your app, initialize the GoogleSignIn instance
164
+ unawaited(
165
+ signIn.initialize(clientId: iosClientId, serverClientId: webClientId));
166
+
167
+ // Perform the sign in
168
+ final googleAccount = await signIn.authenticate();
169
+ final googleAuthorization = await googleAccount.authorizationClient.authorizationForScopes([]);
170
+ final googleAuthentication = googleAccount!.authentication;
171
+ final idToken = googleAuthentication.idToken;
172
+ final accessToken = googleAuthorization.accessToken;
167
173
168
- if (accessToken == null) {
169
- throw 'No Access Token found.';
170
- }
171
174
if (idToken == null) {
172
175
throw 'No ID Token found.';
173
176
}
0 commit comments