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

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

我想檢查用戶是否使用 firebase 登錄

我想檢查用戶是否使用 firebase 登錄

一只斗牛犬 2022-10-21 15:00:00
我有一個帶有身份驗證和 firebase 后端的 React 應用程序。如何檢查用戶是否已登錄?我用 onAuthStateChanged 試過了。但它只返回:這是我的代碼:import * as FirestoreService from '../../firebase/firebase'; useEffect(() => {    let user = FirestoreService.isLoggedIn()                console.log( user)    }, []);現在在firebase文件中: export const isLoggedIn = () => {    return firebase.auth().onAuthStateChanged(function (user) {    if (user) {      console.log("User signed in");          }    else {      console.log("User signed out");          }  });  }我的檢查登錄是否成功:function handleLogin() {     FirestoreService.LoggIn(email, password).then(function (result) {        // result.user.tenantId should be ‘TENANT_PROJECT_ID’.        setloggedIn(true)            }).catch(function (error) {                setloggedIn(false);    });}火力基地文件:    export const LoggIn = (email, password) => {  return firebase.auth().signInWithEmailAndPassword(email, password)    .then(function (result) {      // result.user.tenantId should be ‘TENANT_PROJECT_ID’.      return result;    })    .catch(function (error) {      return error    });}
查看完整描述

1 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

onAuthStateChanged()為用戶登錄狀態的變化添加一個觀察者,但不返回user對象。

在您的情況下,您應該使用該currentUser屬性。如果用戶未登錄,currentUser則為空:

export const isLoggedIn = () => {  
  return firebase.auth().currentUser;
  }


查看完整回答
反對 回復 2022-10-21
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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