CapacitorGoogleAuth
CapacitorGoogleAuth copied to clipboard
Using with Firebase?
Okay, this might come across as a dumb question, but I'm a baby with this stuff so if someone could hear me out I would really appreciate it!
I've got an Ionic app with a Firebase project, and I'm using the CapacitorGoogleAuth. How do I make it so that when a user logs in with Google, they're added to the Firebase list of users? It works fine for the email/password signup that I created, but even though everything seems to work with the Google login, it doesn't add any users to that list.
Hi @tflahert, I can share my current implementation with you that I have in my Ionic App with Angular:
googleAuth() {
return GoogleAuth.signIn()
.then((response: { authentication: Authentication }) => {
// Create Firebase Credentials for Google
return firebase.auth.GoogleAuthProvider.credential(
response.authentication.idToken,
response.authentication.accessToken
);
})
.then((googleCredential) => {
return this.loadingService.present().then(() => {
return this.authLogin(googleCredential).then(() =>
this.loadingService.dismiss()
);
});
})
.catch((error) => {
this.log.error("Google-Error:", error);
});
}
// Login with created credentials
private authLogin(credential: firebase.auth.OAuthCredential) {
return this.loadingService.present().then(() => {
return this.fireAuth
.signInWithCredential(credential)
.then((userCredentials) => {
this.customToastService.showToast(
"auth.toasts.loginSuccess",
"success"
);
})
.catch((error) => {
this.loadingService.dismiss();
});
});
}
Hi,
have you solved this? I use React
same problem: any idea?
Hi,
have you solved this? I use React
I passed the id token returned from CapacitorGoogleAuth to the Firebase Google Auth method outline here: https://firebase.google.com/docs/auth/web/google-signin#expandable-2
Something like this:
try {
const response = await GoogleAuth.signIn();
const idToken = response.authentication.idToken;
const credential = GoogleAuthProvider.credential(idToken);
// Sign in with credential from the Google user.
return signInWithCredential(auth, credential).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.email;
// The credential that was used.
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
});
} catch (err) {
console.error(err);
}
The firebase + cloud console setup is quite tricky. They have to align. Did you set up the SHA-1 fingerprint both in Firebase and your Android Client ID?