oauth 2 refresh in app router #68170
Replies: 1 comment 1 reply
-
|
Components are Server Components by default, there's no directive for that, unless marked with a You can try to use the When your user does login, you do this in a router handler, or server action, and then likely set cookies or something, that's not during SSR. And to refresh the user cookie, you could use middleware, and even do it within server actions or route handlers. It should be rather cheap to check if a user session has expired though, only those who need to refresh their session, would wait a bit longer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's imagine we have server side component in which we get data that is protected and user needs login to access it. something like below:
"use server" const SSRComponent = async()=> { const data = await getData(); }and i as i said, the data is protected and user needs to login to access it and it's possible to access token expires during navigation between pages and you should refresh the access token and set refresh and access token. something like the code below:
const getData = async()=>{ const {access, refresh} = await refreshToken(); cookies().set('refresh', refresh); cookies().set('access', access); }but the problem is that you can't set cookies in the the ssr component. so what is the proper way and performant way to solve this issue becaus calling api call in middleware blocks user from seeing the page and based on server response time, this can affect first contentfull paint and largest contentfull paint.
Beta Was this translation helpful? Give feedback.
All reactions