Ionic:合并到 firebase v3 时身份验证不持久
Ionic: Authentication not persistent when merging to firebase v3
我正在将 ionic 应用程序从 firebase v2 合并到 firebase v3。
当我使用新的 (v3) firebase email/password 登录 API 时,我未通过身份验证,每次重新启动应用程序时都必须登录。
用户在首次登录应用程序时应保持身份验证状态。或者至少这是 firebase v2 中的默认设置 API.
如何保持登录?
谢谢,
约尔根
你应该使用 onAuthStateChanged()
。只要身份验证状态发生变化,就会调用此函数。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
... do other stuff
} else {
// No user is signed in.
... do other stuff
}
});
如果您在打开应用程序时已经登录,或者您调用signInWithEmailAndPassword
,将调用此函数并且user
将包含firebase.auth().currentUser
。
我正在将 ionic 应用程序从 firebase v2 合并到 firebase v3。
当我使用新的 (v3) firebase email/password 登录 API 时,我未通过身份验证,每次重新启动应用程序时都必须登录。
用户在首次登录应用程序时应保持身份验证状态。或者至少这是 firebase v2 中的默认设置 API.
如何保持登录?
谢谢, 约尔根
你应该使用 onAuthStateChanged()
。只要身份验证状态发生变化,就会调用此函数。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
... do other stuff
} else {
// No user is signed in.
... do other stuff
}
});
如果您在打开应用程序时已经登录,或者您调用signInWithEmailAndPassword
,将调用此函数并且user
将包含firebase.auth().currentUser
。