Hello, im using Login extra for users to log into web context. Ideally after successful log in user should be redirected to the page where login form in on. So for example /team/teammember-1/ - this resource is protected so user needs to log in and after login user should end up on /team/teamember-1/.
According to the documentation Login - Login | MODX Documentation, there is an param &loginResourceId- "The resource to direct users to on successful login. 0 will redirect to self. Leave out if using the default unauthorized page."
Observed behavior
In my case it redirects to home page for some reason, also i have tried to pass
trueReferer(which is ID of current resource) param to the chunk with !Login snippet &loginResourceId=[[+trueReferer]] but for some reason snippet cant parse it…
Does anybody had similar issue or know the workaround that?
Do you have a value for the system setting unauthorized_page that is equal to the ID of your homepage?
It could be that there is a problem with the authorization, so the request gets redirected to the unauthorized_page (or maybe even the error_page).
Does the property &loginResourceId work, if you (for testing purposes) redirect to a resource that is not protected?
After you logged in via the Login snippet, can you then manually navigate to the protected resource (or does that also not work)?
When you open the developer tools in the browser, go to the “Network” tab and then try to log in on the front-end. What is the HTTP response status code for the redirect to the homepage?
@jako - i have tried both logged out and in - the same result.
@halftrainedharry&loginResourceId works if i passed static id of the unprotected resource.
Yes i can, after performing the login I’m successfully logged in to web context, however I’m ending up on wrong resource (home page) i guess it a fallback?
[2024-11-07 10:19:53] (ERROR @ public_html/core/src/Revolution/modX.php : 1072) [[+trueReferer]] is not a valid integer and may not be passed to makeUrl()
[2024-11-07 10:19:53] (ERROR @ public_html/core/src/Revolution/modResponse.php : 231) Attempted to redirect to an empty URL.
[2024-11-07 10:19:53] (ERROR @ public_html/core/src/Revolution/modX.php : 1072) [[+trueReferer]] is not a valid integer and may not be passed to makeUrl()
[2024-11-07 10:19:53] (ERROR in resource 581 @ public_html/core/src/Revolution/modLinkTag.php : 114) Bad link tag [[~[[+trueReferer]]]] encountered
If it’s in a snippet and the snippet is uncached, make sure that it runs before the Login snippet gets executed.
It might also be necessary to make the placeholder uncached → [[!+trueReferer]].
So the[[+trueReferer]] is passed as per below: [[!$invLogin? &classes=py-60 content-container &trueReferer=[[+id]] &message=Please log in or register
below to see the content of this tab.`]]``
i have tried to add uncache flag in !Login snippet: [[!Login? &loginTpl=invLoginForm &placeholderPrefix=lg &preHooks=wwdCloudTurnstile &postHooks=`` &errorPrefix=lg.error &errTpl=lgnErrTpl &logoutResourceId=581 &loginResourceId=[[!+trueReferer]] ]]
And now it actually redirect but back to the login page… and I’m successfully logged in… very weird…
In the error log still the same error:
[2024-11-07 11:01:54] (ERROR @ public_html/core/components/login/controllers/web/Login.php : 288) PHP warning: Undefined array key “returnUrl”
[2024-11-07 11:01:54] (ERROR @ public_html/core/src/Revolution/modX.php : 1072) [[!+trueReferer]] is not a valid integer and may not be passed to makeUrl()
[2024-11-07 11:01:54] (ERROR @ public_html/core/src/Revolution/modResponse.php : 231) Attempted to redirect to an empty URL.
[2024-11-07 11:01:54] (ERROR @ public_html/core/src/Revolution/modX.php : 1072) [[+trueReferer]] is not a valid integer and may not be passed to makeUrl()
[2024-11-07 11:01:54] (ERROR in resource 581 @ public_html/core/src/Revolution/modLinkTag.php : 114) Bad link tag [[~[[+trueReferer]]]] encountered
So you include a chunk “invLogin” and pass in [[+id]] as the property trueReferer? And then in the chunk “invLogin” you call Login → [[!Login? &loginResourceId=`[[+trueReferer]]` ]]?
Where do you include “invLogin” and when is [[+id]] set? Is this in a template-chunk for getResources/pdoResources?
[[!If?
&subject=`[[!invAccessChecker? &id=`[[+id]]`]]`
&operator=`==`
&operand=``
&then=`
[[!$invLogin? &classes=`py-60 content-container` &trueReferer=`[[!+id]]` &message=`Please log in or register
below to see the content of this tab.`]]`
]]
Its within a list of “tabs” and some of the tabs are protected - if they are show the login form.
The reason why its uncached its because its in the !If statement and i read somewhere that everything within If should be uncachaed - not sure if that’s true…
Yes in that case i have two form in two separate tabs - and initality they both in the DOM tabs are just working like display none/block…
ohh i have not take this case under consideration… i don’t really control that then…
It’s probably better to have just 1 call to the Login snippet on the page that handles the login request.
To allow to navigate to different resources after a successful login, you probably have to add a new (hidden) field to the login form and send the value with the request.
oh okay… hmm i just found out that according to the documentation the:
actionKey and loginKey might help with that? I’m not sure if i understand that correctly though…