我正在开发一个具有Google Loginthrough功能的应用程序Firebase。我正在尝试借助名为react-native-google-signin. 它是用于 Google 登录的 ReactNative 领域的知名库。
我的问题不在于这个库,但问题是当我使用react-native-google-signin带有 firebase 的库通过谷歌登录时。Firebase 用户并没有保持持久性,我的意思是说,当我在关闭后打开应用程序时FirebaseUser正在获取null. 在我用来通过firebase登录的代码下方,
GoogleSignin.signIn().then(data => {
const credentials = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then() => {
return firebase.auth().signInWithCredential(credentials);
}).catch(error => {
console.log('Error', error);
})
}).then(user => {
console.log('user', firebase.auth().currentUser);
}).catch(error => {
console.log('Error', error);
})
我还检查了 Firebase Docs,尝试使用方法,但在再次打开应用程序后setPersistence()我仍然得到用户。null