如何检查用户是否已登录?

时间:2020-07-10 23:21:29

标签: node.js firebase firebase-authentication

我正在检查用户是否已登录

const firebase = require('firebase-admin')
firebase.auth().onAuthStateChanged((user) =>{
      console.log('message1', user)
      if (user) {
        console.log('exist')
      } else {
        console.log('not exist')
      }
    });

但是我只得到错误:错误:FIREBASE_ERROR

1 个答案:

答案 0 :(得分:0)

您正在使用Admin SDK,它没有登录用户的概念。 Admin SDK中的所有代码都在管理帐户下运行,而不是在Firebase身份验证用户的凭据下运行。

如果要确定在客户端上登录的用户,然后与运行Admin SDK的进程进行通信,则可以通过在客户端上getting the ID token for the user进行操作,然后将其发送到服务器,和decoding and verifying the ID token在服务器上。

另请参阅:

相关问题