-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server actions redirect issue #408
Comments
Looks to be related to this issue vercel/next.js#65893 (comment) |
does not make sense but the solution here amazingly worked for me. vercel/next.js#65893 (comment) redirect("./"); |
This solution is flawed when the server action is triggered from a differently nested path you'll be redirected to the current path which would result in 404. e.g: logout action has redirect('./login') if logout action is triggered at /profile or / you're redirected to /login but better solution I found is to use .get("x-forwarded-host") instead of .get("host") // Get hostname of request (e.g. demo.vercel.pub, demo.localhost:3000)
const hostname = req.headers
.get("x-forwarded-host")!
.replace(".localhost:3000", `.${clientEnv.NEXT_PUBLIC_ROOT_DOMAIN}`);
|
Fixes this issue vercel#408 (comment)
I have a login page in a [domain]/login/page.tsx that calls a server action.
In the login page of a site e.g: http://tenant1.localhost:3000/login
when you successfully logged in it does redirect to http://tenant1.localhost:3000/ but the page shown is the home page of the platform not the tenant but when you refresh manually you get the home page of the tenant.
I have added a console.log in the middleware.
Same log output for redirect("/?test=test") and
redirect('http://tenant1.localhost:3000?test=test')
so it looks like the issue is that redirect in server actions does not care about the subdomain.
Only tested this locally on next v14.2.3
The text was updated successfully, but these errors were encountered: