I am using ```
‘expo-google-app-auth’
to authenticate and log-in to my app. When I am logged in tho it seems another user cannot log in.
Below is the code I am using to accomplish this....how can I have more than one user logged in simultaneously or is it a bug in my code? Does the user have to be signed out before another user can?
First Sign in with google async:
async function signInWithGoogleAsync() {
const result = await Google.logInAsync({
androidClientId: CLIENT_ID
,
iosClientId: CLIENT_ID
,
scopes: [
“profile”,
“email”,
“https://www.googleapis.com/auth/calendar”,
“https://www.googleapis.com/auth/calendar.events”,
],
});
if (result.type === "success") {
onSignIn(result);
return result.accessToken;
} else {
return { cancelled: true };
}
}
Then on success from sign in with google async...sign in to firebase with credentials.
function onSignIn(googleUser, firebaseUser) {
// We need to register an Observer on Firebase Auth to make sure auth is initialized.
let unsubscribe = firebase
.auth()
.onAuthStateChanged(async (firebaseUser) => {
try {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
if (!isUserEqual(googleUser, firebaseUser)) {
// Build Firebase credential with the Google ID token.
// console.log(“GOOGLE USER ID TOKEN”, googleUser);
const credential = firebase.auth.GoogleAuthProvider.credential(
googleUser.idToken,
googleUser.accessToken
);
// Sign in with credential from the Google user.
const result = await firebase
.auth()
.signInWithCredential(credential);
await db.collection("users").doc(result.user.uid).set({
gmail: result.user.email,
profile_picture: result.additionalUserInfo.profile.picture,
first_name: result.additionalUserInfo.profile.given_name,
last_name: result.additionalUserInfo.profile.family_name,
created_at: Date.now(),
access_token: googleUser.accessToken,
});
setAccessToken(googleUser.accessToken);
setFirebase_userId(result.user.uid);
//id(googleUser.accessToken);
console.log("RESULT USER ID", result.user.uid);
//Retreive Calendars from the user using the UserId Returned
await getCalendarsFromUser(result.user.uid);
navigate("HearthCalendar");
//Navigate to next page upon logging in and passing user data to Redux Store
} else {
console.log("User already signed-in Firebase.");
}
} catch (error) {
// Handle Errors here.
let errorCode = error.code;
let errorMessage = error.message;
// The email of the user's account used.
let email = error.email;
// The firebase.auth.AuthCredential type that was used.
let credential = error.credential;
console.log(errorCode, errorMessage, email);
}
});
}