Cloud Functions for Firebase - write to database when a new user created

后端 未结 1 643
余生分开走
余生分开走 2021-02-13 19:14

I am pretty new Cloud Functions for Firebase and the javascript language. I am trying to add a function every time a user created to write into the database. This is my code:

相关标签:
1条回答
  • 2021-02-13 19:54

    I found the problem. The problem is that shouldn't use the ${id}, and I shouldn't have use the child. So the code should look like this:

    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    
    admin.initializeApp(functions.config().firebase);
    
    exports.addAccount = functions.auth.user().onCreate(event => {
        const user = event.data; // The firebase user
        const id = user.uid;
        const displayName = user.displayName;
        const photoURL = user.photoURL;
    
        return admin.database().ref("/users/"+id+"/info/status").set("ok"); 
    });
    
    0 讨论(0)
提交回复
热议问题