慕后森
2023-03-03 09:35:04
我在我的項目中使用 Firebase 身份驗證,我的問題是,只存儲用戶 uid而不是在短時間內過期的刷新令牌有什么問題,這樣我可以讓用戶保持登錄狀態。我正在使用signInWithEmailAndPassword, 方法登錄用戶并從中獲取用戶對象firebase.auth().onAuthStateChangedfirebase.auth().onAuthStateChange(authUser=> setUser(authUser))現在我可以使用authUser.user.uid它并將其存儲在 localStorage 中。我的問題與firebase或任何其他庫無關,但我問的是一般行為,存儲不會過期的東西有什么問題?我的問題是,這樣做有多糟糕?
1 回答

翻過高山走不出你
TA貢獻1875條經驗 獲得超3個贊
Authentication State Persistence您可能想像下面的示例一樣使用:
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
.then(function() {
// Existing and future Auth states are now persisted in the current
// session only. Closing the window would clear any existing state even
// if a user forgets to sign out.
// ...
// New sign-in will be persisted with session persistence.
return firebase.auth().signInWithEmailAndPassword(email, password);
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
在這里了解更多
添加回答
舉報
0/150
提交
取消