<p><code>{% requireLogin %}</code> is intended for use with your own login form on the frontend rather than the standard /admin one. From the docs for <a href="https://craftcms.com/docs/config-settings#loginPath" rel="nofollow noreferrer">loginPath</a>:</p>

<blockquote>
  <p><a href="https://craftcms.com/docs/config-settings#loginPath" rel="nofollow noreferrer">The URI Craft should use for user login on the front-end.</a></p>
</blockquote>

<p>Which means you create your own frontend login form, and set that as the <code>loginPath</code>. 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.</p>

CC BY-SA 3.0
2017-01-11T15:58:31.583Z
Clive, I think you can remove a ? or two :-)
carlcs
CC BY-SA 3.0
2017-01-11T15:51:37.747Z
2017-01-12T14:07:07.350Z
2017-01-12T14:07:07.350Z
Clive Portman
<p>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?</p>

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

CC BY-SA 3.0
2015-03-17T14:26:55.560Z
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
CC BY-SA 3.0
2015-03-17T15:44:59.263Z
Be sure you're testing with a user account that doesn't have CP access as well.
Brad Bell
CC BY-SA 3.0
2015-03-18T15:11:25.040Z
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
CC BY-SA 3.0
2017-01-11T23:04:06.807Z
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
<redirect><password><login>
Password protect whole staging site. Redirect to original page not working
# Password protect whole staging site. Redirect to original page not working

(Asked by: username_0 on 2015-03-17)

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.

**Tags:** redirect, password, login

> **Comments:**
> **username_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?  
> **username_2**: Be sure you're testing with a user account that doesn't have CP access as well.  
> **username_0**: 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.  
> **username_3**: 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.  

---

## 1 answers

### Answer by username_4 on 2017-01-11. Score: 2

`{% requireLogin %}` is intended for use with your own login form on the frontend rather than the standard /admin one. From the docs for [loginPath](https://craftcms.com/docs/config-settings#loginPath):

> [The URI Craft should use for user login on the front-end.](https://craftcms.com/docs/config-settings#loginPath)

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.

> **Comments:**
> **username_5**: Clive, I think you can remove a ? or two :-)  

---

