Implement Redirect Authentication for Google and GitHub Sign-In (#5515)

This commit is contained in:
hunteraraujo
2023-10-03 12:51:49 -07:00
committed by GitHub
parent a41b5ea4a9
commit 0d5c2a98c0

View File

@@ -7,31 +7,24 @@ class AuthService {
clientId:
"387936576242-iejdacrjljds7hf99q0p6eqna8rju3sb.apps.googleusercontent.com");
// Sign in with Google
// Sign in with Google using redirect
Future<UserCredential?> 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<UserCredential?> 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;