Ability to set custom headers just like we can set cookie #71415
Unanswered
ScreamZ
asked this question in
App Router
Replies: 1 comment 2 replies
-
|
Related limitation workaround attempt: Trying to set the response header when a setCookie instruction is detected. Not successful |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm using NextJS app router as my main application, but I'm trying to embed my website partially in a mobile application using react native and webviews.
The login feature is handled natively and I'm able to inject a session cookie in the webview, and initially load the webwiew using a custom request header, that way my user is authenticated on the website.
Now I'm trying to develop a feature to detect session expiration.
How to proceed?
First I'm checking the session when the application starts from native side. And also I'm monitoring the expiration time of the cookie on browser and app side. But polling for cookie expiration is redundant and not very accurate, I rather use some push mechanism.
Now I need to detect manual disconnection and session invalidation.
As I'm using server actions almost everywhere I was thinking about setting a custom response header that the client can intercept and being notified of session removal. As my cookie for authentication is HTTP only, I cannot read the setHeader cookie using JavaScript.
I was surprised that (knowing the limitation about streaming and HTTP headers) I couldn't define a custom header for a response whereas I can set a custom cookie in server action. And again, I'm conscient of the limitation with streaming.
Why is that limitation?
I was expecting to set a
X-Session-Expiredheader to my response that way I can detect missing session.Currently, I'm forced to check for the cookie existence on each fetch request, no matter what, but It could be easier to define a custom header.
I know I could use route handlers, but this would cost a full refactoring. And I couldn't benefit from server actions.
Current workaround
My current workaround is as follow:
Beta Was this translation helpful? Give feedback.
All reactions