From 0d5c2a98c071336e1bb48716cc25d85df2656ced Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Tue, 3 Oct 2023 12:51:49 -0700 Subject: [PATCH] Implement Redirect Authentication for Google and GitHub Sign-In (#5515) --- frontend/lib/services/auth_service.dart | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/frontend/lib/services/auth_service.dart b/frontend/lib/services/auth_service.dart index dac4db90..3cbb3b9c 100644 --- a/frontend/lib/services/auth_service.dart +++ b/frontend/lib/services/auth_service.dart @@ -7,31 +7,24 @@ class AuthService { clientId: "387936576242-iejdacrjljds7hf99q0p6eqna8rju3sb.apps.googleusercontent.com"); - // Sign in with Google +// Sign in with Google using redirect Future signInWithGoogle() async { try { - final GoogleSignInAccount? googleSignInAccount = - await googleSignIn.signIn(); - if (googleSignInAccount != null) { - final GoogleSignInAuthentication googleSignInAuthentication = - await googleSignInAccount.authentication; - final AuthCredential credential = GoogleAuthProvider.credential( - accessToken: googleSignInAuthentication.accessToken, - idToken: googleSignInAuthentication.idToken, - ); - return await _auth.signInWithCredential(credential); - } + final GoogleAuthProvider googleProvider = GoogleAuthProvider(); + await _auth.signInWithRedirect(googleProvider); + return await _auth.getRedirectResult(); } catch (e) { print("Error during Google Sign-In: $e"); return null; } } - // Sign in with GitHub +// Sign in with GitHub using redirect Future signInWithGitHub() async { try { - final GithubAuthProvider provider = GithubAuthProvider(); - return await _auth.signInWithPopup(provider); + final GithubAuthProvider githubProvider = GithubAuthProvider(); + await _auth.signInWithRedirect(githubProvider); + return await _auth.getRedirectResult(); } catch (e) { print("Error during GitHub Sign-In: $e"); return null;