is there a way to get url path from server side?
Unanswered
Sun bear posted this in #help-forum
Sun bearOP
Related to the previous question, I am trying a hack to route to a refresh client page to refresh the token and route back.
I'm failing to get the route from server side to be passed to the refresh page to redirect back to the original page.
I'm failing to get the route from server side to be passed to the refresh page to redirect back to the original page.
9 Replies
Sun bearOP
I have a Next.js webapp, with app router, and am using firebase auth. firebase auth can only refresh cookies on the client side.
The issue is that server side components fetch first, using whatever cookie is available. If the cookie is expired, the fetch will fail on server side, before client side can render and refresh the cookies.
The issue is that server side components fetch first, using whatever cookie is available. If the cookie is expired, the fetch will fail on server side, before client side can render and refresh the cookies.
To work around this issue I found a SO thread suggesting a redirect to a client page with just a component that refreshes the token on load and sets the cookie.
Ideally the refresh page should then redirect back to the page the user was at.
How do I get the pathname on server side so I can give it to the refresh page which will redirect back?
How do I get the pathname on server side so I can give it to the refresh page which will redirect back?
Original message was deleted
Sun bearOP
Please let me know if any more information is required 🙏🏼
@Sun bear Ideally the refresh page should then redirect back to the page the user was at.
How do I get the pathname on server side so I can give it to the refresh page which will redirect back?
Toyger
check headers https://github.com/vercel/next.js/issues/43704#issuecomment-1949887755
next-url should have contain url
next-url should have contain url
Sun bearOP
Thank you! I've tried that but
always gives me
import { headers } from "next/headers";
...
const heads = headers();
const encodedPath = heads.get('next-url')always gives me
nullhttps://github.com/vercel/next.js/issues/43704#issuecomment-1956543431
this comment in that thread few comments down discourages its use
this comment in that thread few comments down discourages its use
@Toyger
@Sun bear <@536484914221285376>
Toyger
still you need to check all of headers not only next-url, and maybe bug already fixed.
otherwise only workaround with middleware either client components that will get url and pass it somewhere
otherwise only workaround with middleware either client components that will get url and pass it somewhere