当前位置: 首页 > 知识库问答 >
问题:

通过Firebase Cloud Functions创建新用户-已创建帐户但无法登录

宰父霖
2023-03-14

我是新来的。

我目前正在开发一个应用程序,使用Vue.jsFirebase身份验证、Firebase实时数据库和Firebase云功能作为后端。应用程序必须包含一个管理员帐户的功能之一,该帐户可以为其他人创建帐户。创建后,新用户会收到一封电子邮件,其中包含登录名和登录密码。

因为注册方法(https://firebase.google.com/docs/auth/web/password-auth)自动重新登录用户到一个新创建的帐户,这显然是不想要的行为,我发现了一种通过云功能创建用户的方法。该代码成功地在firebase身份验证面板中创建了一个帐户,只是我无法登录到新创建的帐户。我收到一条消息:“密码无效或用户没有密码”。

此外,我不确定这是否意味着什么,但使用云函数方法创建的帐户在firebase身份验证面板中没有邮件图标(图片)。

云功能代码:

exports.createUser = functions.https.onCall((data, context) => {
console.log(data)
return admin.auth().createUser({
    email: data.email,
    emailVerified: true,
    password: data.password,
    displayName: data.email,
    disabled: false,
  })
    .then(user => {
        return {
            response: user
      }
    })
    .catch(error => {
        throw new functions.https.HttpsError('failed to create a user')
    });

});

登录代码

signIn: async function(){
  if(this.email && this.password){

    let getUsers = firebase.functions().httpsCallable('getUsers')

    this.feedback = null
    this.spin = true

    let destination = null
    let logedUser = null
    let type = null

    this.feedback = 'Logging in...'

    await firebase.auth().signInWithEmailAndPassword(this.email, this.password)
      .then(response => {
        this.feedback = 'Authorization finished...'
        logedUser = response.user
      })
      .catch( error => {
        this.feedback = error.message
        this.spin = false
      })
//... more code here but I am certain it has nothing to do with the problem.

共有1个答案

公良云
2023-03-14

由于HTTPS可调用函数的异步特性,使用您当前的代码,您将尝试在通过Cloud Function完全创建用户之前登录。

此外,您实际上并没有使用邮件密码参数调用云函数。

根据文档,您应该执行以下操作。

....
let getUsers = firebase.functions().httpsCallable('getUsers')

await getUsers({email: this.email, password: this.password})
  .then(result => {
      return firebase.auth().signInWithEmailAndPassword(this.email, this.password)
  })
  .then(userCredential => {
    this.feedback = 'Authorization finished...'
    logedUser = userCredential.user
    return true
  })
  .catch( error => {
    this.feedback = error.message
    this.spin = false
  })
....
 类似资料:
  • 希望有人能对以下事情有所帮助; 我有一个角度 根据要求,应用程序使用用户名(而不是电子邮件地址)登录应用程序。到目前为止,除了以下场景外,我已经设法让一切正常工作: 当通过Graph API创建帐户时,该帐户的所有者无法重置该帐户的密码。错误是“无法找到提供的用户ID的帐户”。 通过自定义注册策略创建的帐户并非如此,因此我进行了一些比较,发现对于通过Graph API创建的帐户,电子邮件丢失(可以

  • 我试图通过Azure AD Graph API在B2C领域创建一个“localaccount”。 为此,我注册了一个应用程序(通过Azure Active Directory->app registrations(legacy))并添加了“Windows Azure Active Directory”的所有权限。 此外,如果我通过注册流创建了一个新用户,则可以创建一个本地帐户。 有人知道我做错了什

  • 是否可以使用java代码创建/删除windows用户帐户并设置其权限以使其成为管理员帐户、简单用户帐户或来宾帐户?

  • 问题内容: 使用此命令 我尝试登录: 错误是: 我以root用户身份执行此操作,并且确实尝试刷新特权。 我尝试了无数用户,但这似乎行不通。我可以创建没有密码的用户,并且登录有效。命令行和从phpmyadmin 还要检查用户是否在mysql.user中。 布赖恩表演的表演赠款: 问题答案: 您可能会遇到这种永久性的MySQL问题,其中user表中的默认用户之一是,这最终会在表的后面拒绝所有用户。我会

  • 目前,在Windows XP上使用甲骨文DB 11g。以授予 DBA 角色的斯科特用户(非系统)身份登录。根据 Oracle 文档“DBA = 具有管理员选项的所有系统权限”。然后,为什么创建新用户会给出错误“ORA-01031权限不足...”?下面是使用 SQL 开发人员执行的 DDL 命令:

  • 是否可以像使用WordPress用户一样通过编程方式创建客户。显然,WooCommerce用户共享一些相同的WordPress用户字段,还有其他内容需要设置,如账单/邮政地址。 以前有人做到过吗?我在他们网站上的WooCommerce API/函数列表中找不到任何内容。 编辑:刚刚找到这个:http://docs.woothemes.com/wc-apidocs/function-wc_creat