Reputation: 489
So i working with firebase auth and database in order to set new user to data base, if set successful i want to set claims for that user. So it means i have a promise within a promise:
function setUser(user){
// no need for the database code before this, but userRef is set properly
return userRef.set(user)
.then(succ => {
return firebase.firebase.auth().setCustomUserClaims(user.key, {admin: true})
.then(() => {
console.log("setting claims")
return true;
});
})
.catch(err => {
return err
})
}
calling function:
app.post("/register_user",jsonParser,async (req, res) => {
var user = req.body.user;
let result = await fireBase.setUser(user);
res.send(result);
})
What happens is that i get the set on the database but claims are not set nor i can i see the log. I know its a js question and not firebase one. I tried many different ways (with await) but non worked.
Upvotes: 1
Views: 84
Reputation: 497
firebase.firebase
does not seem correct. You need to be using the admin
object which can be initialised using const admin = require('firebase-admin');
This is not part of the firebase
db sdk, but the admin
one. You can also use the userRef.uid
as that gives you the id of the document of the user, if that is what you want, else use your user.key
return admin.auth().setCustomUserClaims(userRef.uid, {
admin: true
}).then(() => {
//on success
});
Upvotes: 1