小编Res*_*lly的帖子

使用云功能在firestore中创建文档

在我的应用程序中验证用户后,我想创建一个云函数,在我的firestore userProfile集合中为它们创建用户配置文件.

这是我的整个index.js文件,用于云功能

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

// The Firebase Admin SDK to access the Firebase Realtime Database. 
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

//function that triggers on user creation
//this function will create a user profile in firestore database
exports.createProfile = functions.auth.user().onCreate(event => {
    // Do something after a new user account is created
    return admin.firestore().ref(`/userProfile/${event.data.uid}`).set({
        email: event.data.email
    });
});
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误

TypeError: admin.firestore(...).ref is not a …
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-functions google-cloud-firestore

6
推荐指数
2
解决办法
7881
查看次数