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

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?

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!

1 Like

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.

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

1 Like

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

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.

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!

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!

No worries here for you!

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