亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

存儲用戶 uid 而不是刷新令牌以保持用戶登錄?

存儲用戶 uid 而不是刷新令牌以保持用戶登錄?

慕后森 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;

  });

在這里了解更多



查看完整回答
反對 回復 2023-03-03
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號