Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth with custom claims?

See original GitHub issue

Is there any way to wait until the custom claims are loaded using ?


Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

afk-mariocommented, Jun 1, 2020

Not 100% sure it works for everyone but this is my current hook

export const useUserWithRole = (auth) => {
  const [userWithRole, setUserWithRole] = useState();
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState();

  useEffect(() => {
    return auth.onAuthStateChanged(async (user) => {
      if (user) {
        try {
          const idTokenResult = await user.getIdTokenResult();
          setUserWithRole({ ...user, role: });
        } catch (e) {
      } else {
  }, [auth]);

  return [userWithRole, loading, error];

Read more comments on GitHub >

github_iconTop Results From Across the Web

Control Access with Custom Claims and Security Rules
Custom authentication is generally used when using a different authentication system with Firebase services, or to augment Firebase Auth with providers that are ......
Read more >
Create Custom Claims - Auth0
To keep your custom claims from colliding with any reserved claims or claims from other resources, give them a collision-resistant name.
Read more >
Configuring custom claims on users - Identity Platform
This document explains how to configure custom claims on users with Identity Platform. Custom claims are inserted into user tokens during authentication.
Read more >
Controlling Data Access Using Firebase Auth Custom Claims
Custom claims are key/value pairs that you can set per user at the server level. They can be defined to give administrative privileges...
Read more >
Customize tokens returned from Okta with custom claims
Add a custom claim to a token · In the Admin Console, go to Security > API. · On the Authorization Servers tab,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found