2

According to the Craft docs {% requireLogin %} on a page should return the user to the same page after login. This doesn't work for me - the returned page is always the one set in 'postLoginRedirect'.

In the config file, I've got this setup:

    'postLogoutRedirect' => 'members/logout',

    'postLoginRedirect' => 'members',

    'loginPath' => 'members/login'

What am I missing?

1 Answer 1

4

I may be missing something here, but you probably just want to remove the postLoginRedirect setting from the config?

You could also try adding {{ redirectInput(craft.app.user.returnUrl) }} to the form.

craft.app.user.returnUrl should return the URL that triggered the login.

3
  • I tried that, but if it's removed the user is sent to the default post login URL.
    – Andrew
    Commented Jun 18, 2020 at 13:08
  • Hi, have updated my answer with another option. craft.app.user.returnUrl should give you the url that you want to redirect to, so setting the {{ redirectInput() }} value to that should sent the user back to the page that triggered the login.
    – dmatthams
    Commented Jun 18, 2020 at 13:38
  • Yes that's done it!
    – Andrew
    Commented Jun 19, 2020 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.