in Education by
Details If you use the function createCustomToken to sign in the user and setting his custom claim, updating the custom claims later using the function setCustomUserClaims will not update the claims even after forcing the idToken to refresh using the function firebase.auth().currentUser.getIdTokenResult(true) How to reproduce? Sign in the user on firebase using a custom token generated with the function createCustomToken including the custom claims firebase.auth().createCustomToken(uid, {myClaim: "test"}).then((customToken) => console.log(customToken)) Sign in the user on the frontend using the custom token // copy paste the customToken manually for testing firebase.auth().signInWithCustomToken(customToken) Update the claim on the backend using setCustomUserClaims firebase.auth().setCustomUserClaims(uid, {myClaim: "updateTest"}) Refresh the idToken on the frontEnd and log the custom claims firebase.auth().currentUser .getIdTokenResult(/*force refresh*/ true) .then((idTokenResult) => { console.log(`custom claims`, idTokenResult.claims) }) You should see that the claim is still { myClaim: "test" } instead of { myClaim: "updateTest" } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Edit: This is actually an intended behavior. The claims set with createCustomToken have a higher priority. The doc mentions it here https://firebase.google.com/docs/auth/admin/custom-claims#set_and_validate_custom_user_claims_via_the_admin_sdk Setting the custom claims separately at sign in instead of using the function createCustomToken to set them will allow you to edit these claims later. Working code: firestore .doc(`users/${uid}`) .get() .then((clientSnapshot) => { // give user the claims he has const { permissions = {} } = clientSnapshot.data() // use setCustomUserClaims to set the claims return auth.setCustomUserClaims(uid, { permissions }) }) // generate the custom token // ⚠️ don't use createCustomToken to set permission as you won't be able to update them .then(() => auth.createCustomToken(uid)) .then((customToken) => { // send the custom token to the frontend to sign the user in return res.status(200).json({ customToken }) })

Related questions

0 votes
    I am getting the error 'Uncaught TypeError: firebase.auth is not a function'. My code was working perfectly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I'd like to do something like outputIdentity.Claims.Add(new Claim("Claim1", "Hi")) However the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    Is there any way to add a custom parameter to identityserver auth request. I tried this way. but it ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am trying to intitialize my Collection View Model which holds a list of [Users] with a firebase snap ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I am going to create a new distribution at CloudFront. Already I have uploaded my SSL certificate at AWS IAM ... for this distribution? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How to install a Custom Jenkins Plugin or a Version of Plugin Not available in Jenkins Update Center?...
asked Jul 17, 2021 in Technology by JackTerrance
0 votes
    On my site, when you log in, I want to keep these sessions alive for 10 hours. Right now my ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    What is the purpose of the Auth tab in the testing platform? (a) To specify credentials (b) To ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    I am using Firebase authentication and react-redux in my app. I added firebase.auth().onAuthStateChanged to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am using Firebase authentication and react-redux in my app. I added firebase.auth().onAuthStateChanged to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    It is possible to use email verification with firebase but instead of sending a link they have to click, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Is this possible? From what I'm seeing, the only way to get options into the the python class is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
0 votes
    I am trying to connect to remote site via https and download some information. I am doing this: library("httr") library("XML") library(RCurl) url...
asked Apr 17, 2022 in Education by JackTerrance
...