Hi Ben, I see you are using a server side redirect in your server action. If you want to redirect users after login, use the browser component and goto action.
Hi Teodor, thank you for your reply, and that is (the browser component) what I would do as a work around. However, the server side redirect has worked for me in the past. maybe it was in a PHP environment rather than NodeJS.
Hey Ben,
We do a browser redirect to a page that contains a ternary operation to direct our users on to their ‘group’ pages, so form success re-directs to this page which contains the following based on a user profile query:
In essence this page is blank, or styled with the background colour and a preloader, then upon the query response redirects accordingly… Could also use such a redirect for a home page link for example.
This way we only edit this page to update any additional group policies or other factors determining their specific group related pages location etc.
I have gone for your example. Thank you for that. It is a pity that the server side redirect does not work I thought it would. That solution would have been far more elegant.
My understanding of redirect within a server action is that the entire process occurs at server level. Redirect effectively transfers execution at server level to another server action and therefore the output is never sent to the browser, it’s a bit like “chaining” server actions. To redirect at browser level then the browser component is needed
The redirect in the server action works fine, if you would check in your network tab then you would see that it redirected your action to the new url and it would show that page in the result. The problem is that you call it with ajax and it nicely follows the redirect, but it doesn’t redirect your browser to that page, that only happens when your browser receives a redirect on loading a page. Exactly like @Hyperbytes says. To get the redirect working you need your browser to load the server action, for example using a normal form posting to it or linking to it.