Add additional data to user profile via firestore functions onCreate

删除回忆录丶 提交于 2021-02-17 07:01:12

问题


I'm trying to automatically create a user data in my firestore db when user sign up through firestore functions. However I got 2 option for sign up. Bussiness account and personal account. If user signup as bussiness then I want to add "usertype = 1" into my document and when personal then "usertype=2" I managed to automaticaly create a document on signup via functions

const functions = require('firebase-functions')
const admin = require('firebase-admin')

admin.initializeApp()

const db = admin.firestore()

exports.createUserData = functions.auth.user().onCreate((user) => {
const uid = user.uid
const email = user.email
const newUserRef = db.collection("user").doc(uid)

return newUserRef.set({
    userId: uid,
    email: email
})
});

But how I can I also pass "usertype" into that function? Or which function to use to do that?


回答1:


No additional information is passed into the functions.auth.user().onCreate( function, so there's no way to distinguish between the two types of users there.

The best you can do is set the user-type from within the client by writing the same document from there. To prevent a race condition, you'll want to move the entire creation of the user-document to the client.



来源:https://stackoverflow.com/questions/55262750/add-additional-data-to-user-profile-via-firestore-functions-oncreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!