You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello all I'm relatively new to this so if this is a basic question please bear with me here. I am creating a nextjs14 app and I'm trying to implement apollo client into the application. the main part of the application is protected by a login that calls to my express backend to get a JWT token. I want to then pass the JWT token in as a header for the graphql queries.
Issue
When the auth is successful the JWT is generated it is available in my apolloClient.ts file which I will provide how I have it configured below but is not available to my ApolloWrapper.tsx file when trying to run a basic query after the re route to the dashboard.
When I am re routed to the protected dashboard route and manually force a refresh the page in my browser then the JWT is present.
Observations / Questions
I'm guessing that when the /dashboard page is rendered or compiled that JWT is not accessible by the browser yet so it just sets it to undefined.
Would it be acceptable to just force a window reload when the user gets re-routed to the /dashboard route?
Am I missing something obvious that I could add to await the rendering of the /dashboard route until the JWT is available and be added to the headers in the ApolloWrapper.tsx file?
I have some hardcoded urls and such just for testing and some logs in there that would be removed once I figure this out
I think the core problem that you have here is that makeClient is only called once for the whole lifetime of your application - anything else would throw away your cache and require a lot of requests to be made again.
Instead of passing a token into your makeClient function, I would recommend that you work with defaultContext as shown in this comment: #103 (comment)
One random observation:
Please don't use ssrMode with this package. It's something that's sometimes made up by ChatGPT because it exists on the normal ApolloClient, but we don't show it anywhere in the docs for this package - you don't need it for streaming SSR and it might even be counterproductive.
Description
Hello all I'm relatively new to this so if this is a basic question please bear with me here. I am creating a nextjs14 app and I'm trying to implement apollo client into the application. the main part of the application is protected by a login that calls to my express backend to get a JWT token. I want to then pass the JWT token in as a header for the graphql queries.
Issue
apolloClient.ts
file which I will provide how I have it configured below but is not available to myApolloWrapper.tsx
file when trying to run a basic query after the re route to the dashboard.Observations / Questions
/dashboard
page is rendered or compiled that JWT is not accessible by the browser yet so it just sets it to undefined./dashboard
route?await
the rendering of the/dashboard
route until the JWT is available and be added to the headers in theApolloWrapper.tsx
file?I have some hardcoded
urls
and such just for testing and some logs in there that would be removed once I figure this outProject Versions
Folder Layout
apolloClient.ts
ApolloWrapper.tsx
Layout.tsx
: app/(root)/layout.tsxThe text was updated successfully, but these errors were encountered: