Redirect does not redirect

Wappler Version : 4.3.0
Operating System : Windows
Server Model: NodeJS
Database Type: SQLite
Hosting Type: Custom

Expected behavior

Redirect to named page

Actual behavior

Not redirected. The form does not hide meaning that there is an error. However no error message is shown.

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.

Server side redirects are something different and they are used in cases like oauth2 server side authorization actions.

OK, that makes sense. I think I did use it in that context in the past. Thanks for reminding me…

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:

<dmx-serverconnect id="CheckDirect" url="dmxConnect/api/users/profiles/LoggedInUserProfile.php" dmx-on:success="Browser.goto(CheckDirect.data.User[0].usrGroup == '3' ? 'index-office.php' : CheckDirect.data.User[0].usrGroup == '6' ? 'dashboard_owner' : CheckDirect.data.User[0].usrGroup == '9' ? 'dashboard_subscription' : CheckDirect.data.User[0].usrGroup == '2' ? 'i4m_admin_console' : CheckDirect.data.User[0].usrGroup == '4' ? 'dashboard_tenant' : 'index.php')" dmx-on:unauthorized="Browser.goto('index.php')"></dmx-serverconnect>

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.

Thank you @Dave. That is the way I would probably go as well.

Yet, I do not understand why the server side does not work.

The JSON file shows:

image

The core module shows:

image

All it needs to redirect is something like:

app.get('*' , redirect);

OK. I may be wrong, but to dismiss the case without a reason why the server side redirect is not fit for the task, is not good enough.

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.

Hi Ben

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

2 Likes

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.

4 Likes

Thank you, great explanations from both, Brian and @patrick. This is something that I can definitely live with.

2 Likes