第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Firebase 不保留身份驗(yàn)證狀態(tài)

Firebase 不保留身份驗(yàn)證狀態(tài)

動(dòng)漫人物 2023-08-24 10:24:17
我想知道如何使用 firebase 保持身份驗(yàn)證狀態(tài)。我正在做的是嘗試設(shè)置持久狀態(tài),我這樣做:login.addEventListener('click', function (e) {    e.preventDefault();    var email = emailInput.value;    var password = passwordInput.value;    firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)    .then(function() {        auth.signInWithEmailAndPassword(email, password)        .then(function (user) {         })        .catch(function (error) {                alert(error);        });    })});問題是,當(dāng)我刷新網(wǎng)絡(luò)應(yīng)用程序時(shí),會(huì)話似乎不會(huì)持續(xù)。它將用戶重定向回登錄屏幕,這根本不是所需的輸出。所需的輸出是保存用戶的會(huì)話,并且用戶能夠?yàn)g覽應(yīng)用程序而不會(huì)出現(xiàn)被迫再次登錄的問題。我正在關(guān)注 firebase 文檔:https://firebase.google.com/docs/auth/web/auth-state-persistence
查看完整描述

1 回答

?
當(dāng)年話下

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊

如果您想知道用戶之前在新頁(yè)面加載時(shí)是否登錄過您的網(wǎng)站,您應(yīng)該使用身份驗(yàn)證狀態(tài)觀察器來接收回調(diào),該回調(diào)會(huì)在首次知道用戶登錄時(shí)通知您。它不會(huì)觸發(fā)頁(yè)面加載時(shí)立即 - SDK 需要一些時(shí)間來加載用戶帳戶并確定其是否有效。

firebase.auth().onAuthStateChanged((user) => {

? if (user) {

? ? // User is signed in, see docs for a list of available properties

? ? // https://firebase.google.com/docs/reference/js/firebase.User

? ? var uid = user.uid;

? ? // ...

? } else {

? ? // User is signed out

? ? // ...

? }

});

不要用于firebase.auth().currentUser確定用戶之前是否已登錄。頁(yè)面加載時(shí)它最初始終為空。

查看完整回答
反對(duì) 回復(fù) 2023-08-24
  • 1 回答
  • 0 關(guān)注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)