I have a redirect setup after the user logs in. My APIs look like this;
A security restrict API, if a user is not logged in, saves the $_SERVER.PATH.INFO in a session variable on the server side before the security restrict.
On the login success, once the user is redirected to redirect_path.
The issue that I have is that if the requested URL contains a query parameter, then redirects works and loads the page, but does not load the query . For example, if the requested URL is;
and when the user tries to access the link, it sends them to the login page and then the user gets redirected to the link. I followed Ken’s process here: Nodejs redirect to intended URL after login
I can get it to work, however the issue is that PATH_INFO or URL do not pass on the URL Query Parameter value.
That helps, now I know what you are trying to do.
Had a quick look at kens solution and, while I havnt tested, it looks like it assumes you are using a routed URL. I assume there is a reason why you are not using routing?
When I get in front of a computer I will see if I can work out a fix.
Problem with the method here is that the url returned is that of the currently running script I.e. the api action, not the page itself. To get the page url is a little more complex.
Currently at medical appointment at present but will do video tutorial on how to do that on return.
If you try to capture the URL or parameters from your page using $_SERVER.PAGE_REF or parameters from $_SERVER.QUERY_STRING the technically correct details are returned BUT that is not actually what you may need as the values returned are that of the API action, not the content page details.
So requesting $_SERVER.PAGE_REF from with the API workflow basically returns the name of the workflow API.
To get the details of the content page which you are on (which you need to return to), you need to capture these details from the corresponding LAYOUT page.
The easiest way is to add some code to the page.
say we want the PATH_INFO and the QUERY_STRING of the current page we would:
(I will take this in stages)
Assign the SERVER variable to variables in the layout page
You now have the full server path including parameters in the variable which we can echo in the content page or save wherever we want.
so it we run, for example
I think each one of us is doing or thinking differently
On my websites, any Security Restrict that redirects is applied directly on the page (Server-Side Rendered) instead of being on a Server Action. Therefore, I always have access to $_SERVER.QUERY_STRING, as I’m not using a Server Connect/Server Action combination
In regards to Hyperbytes suggestion, I want to mention some browsers might be configured to omit the referrer header (because the user configured as such), therefore making $_SERVER.PAGE_REF empty
Valid comments, the security restrict is an important option for doing this.
I confess when I saw the url with id={{looks like a uuid} I assumed authentication was user level, not role level and security restrict was not appropriate but I may have assumed wrong.
Either way, it’s a useful tutorial on accessing server vars from a page