'GoogleSignIn Authentication in React Native
I'm confused related to the GoogleSignIn Logout first I've managed to SignIn my google account, the problem is when I logout my google account, and SignIn again the previous account that you login before it didn't ask the password like the image below when I click one of user account it will go to my home screen directly instead asking password for that google account since I've already logout the account in my app.
This is my logout function I tried the code below it works in some other way but my concern is since I've already logout the account it should not directly go to homepage when SignIn again ask password to the user or remove user when logout? What is the best way should I do, do I correcly implement it?
const [user, setUser] = useState(null);
logout: async () => {
try {
await GoogleSignin.revokeAccess();
await GoogleSignin.signOut();
setUser({ user: null });
await auth().signOut();
} catch (e) {
console.log(e);
}
},
GoogleSign function
return (
<AuthContext.Provider
value={{
user,
setUser,
googleLogin: async () => {
try {
// Get the users ID token
const Token = await GoogleSignin.signIn();
const {idToken} = Token;
// Create a Google credential with the token
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
// Sign-in the user with the credential
await auth().signInWithCredential(googleCredential)
.catch(error => {
console.log('Something went wrong with sign up: ', error);
});
} catch(error) {
console.log({error});
}
},
}}>
{children}
</AuthContext.Provider>
);
Solution 1:[1]
Short Answer: Your code is completely fine!
Long Answer: This is completely normal behaviour and is intended to be. If you want to Sign Out completely you would have to go into the settings of the corresponding google account and sign out from that device. (Manage Google Account => Security => My Devices => Logout)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maximilian Dietel |

