I get this error when I register a new account. The code I use:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.afterRegFunction = functions.auth.user().onCreate((user) => {
var randInt = (Math.floor(Math.random() * 8) + 1);
var userObject = {
u_n : user.uid, // user nickname
u_n_c : admin.database.ServerValue.TIMESTAMP, // next date to change nick
u_a : randInt.toString(), // user avatar
u_a_c : admin.database.ServerValue.TIMESTAMP, // next date to change avatar
d : admin.database.ServerValue.TIMESTAMP, // date the account was created
u_p : 0 // user points
};
admin.database().ref('userInfo/' + user.uid).set(userObject);
admin.database().ref('nicknames/' + user.uid).set(user.uid);
});
I'm getting Function finished with status: 'error' in the logs and there isn't anything added in the database.
console.log(user);as the first line of the function, before thevar randIntline, it would just print outnulltoo, but sometimes weird things happen... I'd also try out aconsole.log(typeof user);and see if that tells us anything either.admin.initializeApp(functions.config().firebase);was changed to be justadmin.initializeApp();... assuming you're on version 1.0 or later, try updating your code to initialize the SDK with the neweradmin.initializeApp();instead