Nextjs-auth0: Example client side with ApolloClient header token

Created on 3 Feb 2020  路  4Comments  路  Source: auth0/nextjs-auth0

Describe the problem you'd like to have solved

I am having difficulty figuring out how to use this library with Apollo Client.

Detail: I have a nextjs app with accesses an external api (hasura) which require JWT authentication. I would love a best practice example (that ideally does not use local storage) for passing a JWT token (specifically hasura uses the idToken) in the request header from apollo client

Describe the ideal solution

The ideal solution would be an example showing a best practice way to pass the token from an API route to the front end without using express and then showing what the apollo client looks like

Alternatives and current work-arounds

Note I can think of several ways to do this. Eg. have a getToken function which

  • Gets the token from localStorage
  • Or calls an api endpoint which would give a response using the auth0.getSession method

What I am looking for is best preactice/secure as possible.

Sorry I am relatively newbie.

Additional context

Add any other context or screenshots about the feature request here.

All 4 comments

@shansmith01 Have you figured out what should be the best practice? So I think the issue title could be even changed since basically we need just an example of how to properly use access token from the client side, or any clarifications about why everything should be hidden behind nextjs api routes.

@lnikell have you found a solution by any chance? without using the proxy?

@serendipity1004 I decided to move to https://github.com/iaincollins/next-auth and stop trying to get anything from Auth0 or their support.

Hi all, please check out the Access an external API from an API route example from the new v1.0.0-beta.0 release. The issues https://github.com/auth0/nextjs-auth0/issues/67 https://github.com/auth0/nextjs-auth0/issues/55 might also be useful for Apollo Client users.

any clarifications about why everything should be hidden behind nextjs api routes.

We have included information about this in the README of the new beta.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mustafaKamal-fe picture mustafaKamal-fe  路  5Comments

synoptase picture synoptase  路  6Comments

RyGuyM picture RyGuyM  路  5Comments

serendipity1004 picture serendipity1004  路  3Comments

flapjackfritz picture flapjackfritz  路  6Comments