I am making a flutter app with regular login as well as Login with Google functionality using Google Oauth v2 and Supabase. I have tested login with google on local development as well as my production website but the login with google featuere only works locally
Here is my code for Login with Google using Supabase's oauth features:
// --- Sign In with Google ---
Future<void> _googleSignIn() async {
setState(() => _isLoading = true);
try {
final serverClientId = dotenv.env['GOOGLE_SERVER_CLIENT_ID'];
final iosClientId = dotenv.env['GOOGLE_IOS_CLIENT_ID'];
if (serverClientId == null || iosClientId == null) {
throw 'Google Client IDs are not configured in your .env file.';
}
final GoogleSignIn googleSignIn = GoogleSignIn(
clientId: kIsWeb ? serverClientId : (Platform.isIOS ? iosClientId : null),
serverClientId: kIsWeb ? null : serverClientId,
);
final googleUser = await googleSignIn.signIn();
final googleAuth = await googleUser!.authentication;
final accessToken = googleAuth.accessToken;
final idToken = googleAuth.idToken;
if (idToken == null) {
throw 'No ID token from Google!';
}
await supabase.auth.signInWithIdToken(
provider: OAuthProvider.google,
idToken: idToken,
accessToken: accessToken,
);
} catch (error) {
_showErrorSnackBar('Google Sign-In failed: ${error.toString()}');
} finally {
if (mounted) {
setState(() => _isLoading = false);
}
}
}
I made sure to enable all my client ids (GOOGLE_SERVER_CLIENT_ID, GOOGLE_IOS_CLIENT_ID) on Google Cloud as well as store them in a local .env
I built my app using flutter build web and used peanut to push to a production branch that cloudflare hosts as cloudflare pages.
is there any reason why this shouldn't be working?
I tried adding my domain, and all subdomains I could be using to my google cloud Authorized Javascript Origins as well as Authorized redirect URIs for my web client.