【问题标题】:firebase onAuthStateChanged user should not be null [closed]firebase onAuthStateChanged 用户不应为空 [关闭]
【发布时间】:2021-03-02 22:27:44
【问题描述】:

服务器

admin.auth().createCustomToken(uuid)
.then((customToken) => {
  admin.auth().createUser({
      email: 'user@example.com',
      emailVerified: false,
      phoneNumber: '+11234567890',
      password: 'secretPassword',
      displayName: 'John Doe',
      photoURL: 'http://www.example.com/12345678/photo.png',
      disabled: false
    })
    .then((userRecord) => {
      console.log('Successfully created new user:', userRecord.uid);
      res.redirect(`http://localhost:3000?token=${customToken}`);  
    })
    .catch((error) => {
      console.log('Error creating new user:', error);
    });
})

客户

firebase.auth().signInWithCustomToken(token)
.then(() => {
  firebase.auth().onAuthStateChanged((user) => {
    console.log(user.email); // is null.
  });
})

我需要在服务器上使用 admin.auth().createUser({})。

但是,它不起作用。

我不知道怎么用。

我想连接到另一个 sns 服务。

【问题讨论】:

    标签: javascript node.js firebase-authentication firebase-admin


    【解决方案1】:

    我认为如果您将客户更改为:

    firebase.auth().signInWithCustomToken(token)
    .then((user) => {
       console.log(user.email);
    })
    

    你也可以单独拥有这个

    firebase.auth().onAuthStateChanged((user) => {
        console.log(user.email); 
    });
    

    如果有帮助的话,你基本上应该在登录时打印两次用户电子邮件。

    【讨论】:

      猜你喜欢
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 2020-08-06
      • 2021-08-19
      • 2021-04-28
      • 2020-11-15
      • 2016-12-29
      相关资源
      最近更新 更多