无法在Firestore中将数据正确添加到自定义用户集合 [英] Unable to add data to custom User collection properly in Firestore

查看:25
本文介绍了无法在Firestore中将数据正确添加到自定义用户集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将几个用户数据添加到我自己同时创建的Firestore Authenticatedced用户列表和 users 集合中,但是效果不佳. users 集合仅会更新一部分.

I'd like to add several user data to firestore Authenticateced user list AND to users collection which I created by myself at same time, but it does't go well. users collection are updated only its part of it.

// javascript
users: [
  {email: "n_0@example.com", username: "user0"},
  {email: "n_1@example.com", username: "user1"},
  {email: "n_2@example.com", username: "user2"},
  {email: "n_3@example.com", username: "user3"},
  {email: "n_4@example.com", username: "user4"}
]

代码

// javascript

import * as app from 'firebase/app'
import 'firebase/auth'

const config = JSON.parse(process.env.VUE_APP_FIREBASE_CONFIG)

app.initializeApp(config)

export const firebase = app
export const auth = app.auth()

function asyncCreateUser(user) {
  return auth.createUserWithEmailAndPassword(
    user.email,
    'password'
  ).then(function (createdUser) {
    console.log('---')
    console.log('user.email', user.email)
    console.log('createdUser', createdUser.user.email)
    const ref = usersRef.doc(createdUser.user.uid)
    return ref.set(user)
  })
}
this.users.map(user => asyncCreateUser(user))

结果

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆