Next.js Discord

Discord Forum

Refreshing accessTokens

Unanswered
Ruyy posted this in #help-forum
Open in Discord
Hey everyone, I need some help with this scenario I've been puzzling over.

Picture this: you've got a project where user authentication relies on an accessToken that expires after an hour. You're handling refreshToken on your middleware (that runs everytime a route changes). Now, consider a situation where within a single route, there's a map that continuously polls data every 15 seconds without exiting the route. How do you ensure the user's accessToken is refreshed automatically without requiring manual intervention?

If y'all need more context, I can send code gists.

2 Replies

Could you route the polling through another route that goes through the middleware?
@Matsor Browncoat Could you route the polling through another route that goes through the middleware?
I dont think soo...

Here is the current flow.


<InteractiveMapContainer /> // A Server container that prop drills data fetched in the server to the client component.

<InteractiveMap /> // A Client componenet that takes the initial data and uses it in a useQuery hook with a refetch argument.