# How to have the login page as the default if a user is not logged in

**URL:** <https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [November 29, 2022, 1:12pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295 "2022-11-29T13:12:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![timohuennebeck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timohuennebeck/32/13404_2.png) [@timohuennebeck](https://community.auth0.com/u/timohuennebeck)\
**Post date:** [November 29, 2022, 1:12pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/1 "2022-11-29T13:12:25Z")

</div>

I’ve just implemented the login and register functionalities for an SPA Rect app using auth0.

I’d like to render the auth0 login page straight away when a user is not logged or registered.

Right now I just have a button on a “landing page” which the user can click to then be redirected to the auth0 login page. And, if a user is logged it then renders the react router dom content.

How can I ensure that I don’t show the landing page but rather be automatically on the auth0 log in page if someone isn’t logged in or registered?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 29, 2022, 2:30pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/2 "2022-11-29T14:30:17Z")

</div>

Hey there!

Can you let us know what resources have you been following in your implementation? Based on that we should be able to advise something here. Thank you!

---

<div class="post-metadata">

**Author:** ![timohuennebeck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timohuennebeck/32/13404_2.png) [@timohuennebeck](https://community.auth0.com/u/timohuennebeck)\
**Post date:** [November 29, 2022, 3:11pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/3 "2022-11-29T15:11:29Z")

</div>

Hi Konrad! Sure thing, sorry about that.

It’s jus the quick start guide which pops up when I select which technology I’m using for the single-page application. In this case React.

Not sure if you’ll be able to see it as you need to be logged in I believe to see it.

[https://manage.auth0.com/dashboard/us/dev-zapksw78lj5vrfgb/applications/sMARsqfXx49GTDnciIuAkz0fc7gqKh5k/quickstart](https://manage.auth0.com/dashboard/us/dev-zapksw78lj5vrfgb/applications/sMARsqfXx49GTDnciIuAkz0fc7gqKh5k/quickstart)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 29, 2022, 3:36pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/4 "2022-11-29T15:36:47Z")

</div>

Got it! Let me follow up with the quickstart maintainers on that front and will get back to you soon!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 29, 2022, 4:07pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/6 "2022-11-29T16:07:26Z")

</div>

So it’s actually a bit tricky. You would potentially need to put some logic on your top-level component, likely App to always trigger the login action if the user is not authenticated

---

<div class="post-metadata">

**Author:** ![timohuennebeck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timohuennebeck/32/13404_2.png) [@timohuennebeck](https://community.auth0.com/u/timohuennebeck)\
**Post date:** [November 29, 2022, 4:25pm UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/7 "2022-11-29T16:25:12Z")

</div>

Yeah I was thinking something similar before. Basically, what I did was to put the loginWithRedirect() into a useEffect so that when the page was initially rendered it automatically redirected the user.

But the issue with this was then when I then clicked on login it redirected me to the routing page which was correct but then it somehow caused and infinite loop and logged me out again.

Here’s what I got going on right now. I guess I’ll just create a landing page where I’ll put the login button. Shouldn’t be a big deal.

 ![Screenshot 2022-11-29 at 5.31.31 pm](https://global.discourse-cdn.com/auth0/original/3X/f/2/f2efdeb9aadce572bb7bacbccbb36fd2fc2da8c7.png)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 30, 2022, 10:42am UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/8 "2022-11-30T10:42:10Z")

</div>

Make sense, thanks for sharing it! I’m still discussing it with our engineers so maybe I’ll be able to share some more specific approach soon!

---

<div class="post-metadata">

**Author:** ![timohuennebeck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timohuennebeck/32/13404_2.png) [@timohuennebeck](https://community.auth0.com/u/timohuennebeck)\
**Post date:** [November 30, 2022, 10:44am UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/9 "2022-11-30T10:44:00Z")

</div>

Thanks, Konrad! Actually, it’s fine now. I just decided to quickly create a landing page for it. Meaning, there’s no need anymore to have the login page as the first page. Thanks for your help tho!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 30, 2022, 11:09am UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/10 "2022-11-30T11:09:29Z")

</div>

No worries here for you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 14, 2022, 11:09am UTC](https://community.auth0.com/t/how-to-have-the-login-page-as-the-default-if-a-user-is-not-logged-in/95295/11 "2022-12-14T11:09:36Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
