简体   繁体   中英

How to create firestore document on user sign up

I am trying to create a firestore document on user signup. the user is recorded after sign up but the document is not created. Everthing works well except the fact that the document is not created

import { db } from '../Firebase/Firebase';

    const handleSignup = (e) => {
        e.preventDefault()
        createUser(email, password)
            .then(() => {
                db.collection('users').doc(currentUser.uid).set({
                    boards:[]
             })
                seterror(null)

            })
            .catch(error => {
                seterror(error)
            })
    }

Everything looks fine try seperating boards first

import { db } from '../Firebase/Firebase';
const addBoards = {
        boards : [ ]
}
    const handleSignup = (e) => {
        e.preventDefault()
        createUser(email, password)
            .then((user) => {
                db.collection('users').doc(user.user.uid).set(addBoards)
                seterror(null)

            })
            .catch(error => {
                seterror(error)
            })
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM