Muk*_*tro 3 sign firebase react-native
我通过本机反应并使用 rnfirebase 与 google firebase 身份验证连接来开发应用程序。我已经通过谷歌按钮登录代码,如下所示。
const _signIn = async () => {
setInitializing(true);
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
const credential = auth.GoogleAuthProvider.credential(
userInfo.idToken,
userInfo.accessToken,
);
return auth()
.signInWithCredential(credential)
.then(response => {
const uid = response.user.uid;
const data = {
uid: uid,
email: userInfo.user.email,
fullname: userInfo.user.name,
bio: 'I am ok ..',
username: uid.substring(0, 8),
};
const usersRef = firestore().collection('users');
usersRef
.doc(uid)
.get()
.then(firestoreDocument => {
if (!firestoreDocument.exists) {
usersRef
.doc(data.uid)
.set(data)
.then(() => {
RNRestart.Restart();
})
.catch(error => {
setInitializing(false);
Alert.alert(JSON.stringify(error.message));
});
} else {
setInitializing(false);
}
})
.catch(error => {
Alert.alert(JSON.stringify(error.message));
console.log('Error getting document:', error);
});
});
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
setInitializing(false);
Alert.alert('Sign in canceled');
} else if (error.code === statusCodes.IN_PROGRESS) {
setInitializing(false);
Alert.alert('Signin in progress');
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
setInitializing(false);
Alert.alert('PLAY_SERVICES_NOT_AVAILABLE');
} else {
setInitializing(false);
Alert.alert(JSON.stringify(error.message));
}
} };
Run Code Online (Sandbox Code Playgroud)
在 IOS 中,当我以新/注册用户身份登录时,应用程序始终显示 google 登录页面。所以我可以选择我想使用的帐户。像这样:
但在 Android 中,Google 登录页面仅显示用户第一次登录。之后,如果用户从应用程序注销,并且他想通过 google 按钮再次登录,则用户可以直接使用最后一个 gmail 转到主应用程序。所以在android中,如果我之前登录过,我无法切换/使用另一个帐户。
每次用户通过android中的google按钮登录时,如何显示google登录页面?谢谢。
在你的注销函数中,如果用户是通过Google登录的,你需要实现google注销函数:
GoogleSignin.signOut();
更好的方法是同时撤销访问权限,因此完整的注销功能可以是:
等待 GoogleSignin.revokeAccess();
等待 GoogleSignin.signOut();
| 归档时间: |
|
| 查看次数: |
2420 次 |
| 最近记录: |