Is it possible to perform a redirect in middleware when executing a server action from the client? If so, how? #68893
Unanswered
yongholeeme
asked this question in
App Router
Replies: 0 comments
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.
-
$ next info
Is it possible to perform a redirect in middleware when executing a server action from the client? If so, how?
I'm building a middleware to redirect to A page (this is other web site, assume https://google.com) if a session expired. In general, routing in app router works well (if the session expired, redirection to A page works well). However, I encountered a problem.
Let's assume a situation where the page has loaded and the session has expired after some time without refreshing. In this case, when a server action is executed, we expected the middleware to redirect to page A as mentioned above. However, in reality, the redirection did not occur.
I compared between
A: redirect in middleware when server action is executedandB: redirect in server action when server action executed. I found the difference, response status.A: redirect in middleware when server action is executedB: redirect in server action when server action executedI think if a client component execute a server action and redirected by middleware, middleware should return 303 to redirect by router like
B. redirect in server action when server action excutedThen, I've made an workaround to let client redirect making 303 response and
x-action-redirectheader in my app.Is it possible to perform a redirect in middleware when executing a server action from the client? If so, how can I achieve this without using the workaround?
Beta Was this translation helpful? Give feedback.
All reactions