I'm trying to password protect a staging site. So I've put a {% requireLogin %} at the top of my _layout.html inside of a conditional tag. It's working except the redirect after login always goes to the dashboard instead of the original page. What am I doing wrong?

I'm aware of the possibility of using htaccess protection, but I think doing it the "Craft way" is nicer.

  • 1
    What version of Craft are you using (Personal Client or Pro)? Is your login form on the front end? Or are you using the standard /admin control panel login? – Steve Rowling Mar 17 '15 at 14:26
  • Be sure you're testing with a user account that doesn't have CP access as well. – Brad Bell Mar 17 '15 at 15:44
  • I'm using the Pro-Version and the standard /admin login. So it's not supposed to work for users with CP access as well? Would be nice if that was configurable. – Andreas Mar 18 '15 at 15:11
  • Are you visiting the site without "www" and have "www" as part of your siteUrl in settings or vice versa? I once had a redirect like you are describing and think that was the cause. – Wolfram Gehring Jan 11 '17 at 23:04

{% requireLogin %} is intended for use with your own login form on the frontend rather than the standard /admin one. From the docs for loginPath:

The URI Craft should use for user login on the front-end.

Which means you create your own frontend login form, and set that as the loginPath. As you don't have that, it's defaulting to the default login instead, which redirects users to the admin dashboard instead of the page they were on.

  • Clive, I think you can remove a ? or two :-) – carlcs Jan 11 '17 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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