Access custom claims on the client

286 views
Skip to first unread message

Thank_You

unread,
Sep 6, 2018, 12:08:33 AM9/6/18
to Firebase Google Group
I need to access custom claims on the client, but cannot.  
The docs indicate to use firebase.auth().currentUser.getIdTokenResult()
For over a year I have had zero luck getting anything from firebase.auth().currentUser.getIdTokenResult()
The only way I am able to access user info from the client is firebase.auth().onAuthStateChanged(function(user) 


This code does not work.  Always returns undefined.  

firebase.auth().currentUser.getIdTokenResult()
 
.then((idTokenResult) => {
     
// Confirm the user is an Admin.
     
if (!!idTokenResult.claims.admin) {
       
// Show admin UI.
       showAdminUI
();
     
} else {
       
// Show regular user UI.
       showRegularUI
();
     
}
 
})
 
.catch((error) => {
    console
.log(error);
 
});

Hiranya Jayathilaka

unread,
Sep 6, 2018, 12:55:02 PM9/6/18
to fireba...@googlegroups.com
We use getIdToken() in one of our codelabs: 


This works as far as I can see. Not sure if there's an issue with getIdTokenResult().




--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c44c9133-02e8-411d-8fa5-3346fa71662b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Hiranya Jayathilaka | Software Engineer | h...@google.com | 650-203-0128

Kiana McNellis

unread,
Sep 7, 2018, 12:28:34 AM9/7/18
to fireba...@googlegroups.com
What is firebase.auth().currentUser returning?

-Kiana
Reply all
Reply to author
Forward
0 new messages