I'm creating all users from Firebase console, Now I wanted copy all users to realtime db under users
node.
Below is my Google cloud function
exports.getAllUsers = functions.https.onRequest((req, res) => {
cors(req, res, () => {
app.auth().listUsers(1000)
.then((listUsersResult) => {
var db = admin.database();
var ref = db.ref("users");
const usersRef = ref.child('users');
usersRef.set(listUsersResult, { merge: true } );
ref.once("value", function (snapshot) {
console.log(snapshot.val());
});
// admin.database().ref('users').set(listUsersResult, { merge: true })
res.send(listUsersResult);
})
.catch(function (error) {
console.log('Oh no! Firebase listUsers Error:', error);
});
});
});
By using firebase-admin
, I could get all the users list but When I tried to update the DB i'm getting the below error
Oh no! Firebase listUsers Error: Error: Reference.set failed: onComplete argument must be a valid function.
How can I fix this?