Skip to content

How To Use Angular Interceptor With Firebase Authentication #745

Answered by ewwwgiddings
ewwwgiddings asked this question in Q&A
Discussion options

You must be logged in to vote

Found a solution. I've decided to use this library:
https://www.npmjs.com/package/@auth0/angular-jwt

With my tokenGetter as:

export async function tokenGetter(): Promise<string | null> {
  try {
    const { token } = await FirebaseAuthentication.getIdToken({ forceRefresh: false });
    return token || null;
  } catch {
    return null;
  }
}

And registration as:

JwtModule.forRoot({
    config: {
      tokenGetter: tokenGetter,
      allowedDomains: ["example.com"],
      disallowedRoutes: ["http://example.com/examplebadroute/"],
    },
})

Seems like it will get the token locally on each request unless it needs refreshing.

If anyone else has any better way to do it I'm all ears.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ewwwgiddings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant