【问题标题】:firebase google authentication with token带有令牌的firebase google身份验证
【发布时间】:2021-10-30 09:16:24
【问题描述】:

我是 reactjs 世界的新手 我正在开发一个需要 reactjs 和 firebase 连接的小项目 我正在研究firebase google身份验证,我已经实现了一小部分,如下所示,

LoginPage.js

import { auth,provider } from '../firebase'

const loginMethod=()=>{
        auth.signInWithPopup(provider).then((result)=>{
            dispatch(
                setVariableInfo({
                    var1:result.user.displayName,
                    var2:result.user.email,
                    var3:result.user.photoURL
                })
            )
        })
    }

使用上面的代码,当我点击浏览器的 url 时,我可以看到一个弹出窗口,我可以成功地使用 google 帐户进行身份验证。但是当我尝试刷新 url 时,它再次弹出并要求我使用谷歌帐户进行身份验证。

如何实现与 youtube 或 gmail 实现的相同的功能?我们如何使用令牌对用户进行身份验证??

请帮忙,在此先感谢

【问题讨论】:

    标签: reactjs oauth-2.0 firebase-authentication jwt


    【解决方案1】:

    页面刷新请检查用户是否登录

    import { getAuth, onAuthStateChanged } from "firebase/auth";
    
    const auth = getAuth();
    onAuthStateChanged(auth, (user) => {
      if (user) {
        // User is signed in, 
        const uid = user.uid;
        // ...
      } else {
        // User is signed out
        // ...
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-17
      • 1970-01-01
      • 2022-07-16
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 2013-10-12
      相关资源
      最近更新 更多