# Go to login page without pressing a button

**URL:** <https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881>\
**Category:** Get Help\
**Tags:** login, auth0\
**Created:** [March 15, 2022, 5:56am UTC](https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881 "2022-03-15T05:56:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![msuguitan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/msuguitan/32/14222_2.png) [@msuguitan](https://community.auth0.com/u/msuguitan)\
**Post date:** [March 15, 2022, 5:56am UTC](https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881/1 "2022-03-15T05:56:53Z")

</div>

Hi everyone,

I am wondering how to go to login page with pressing a button.  
In the example code that is always provided, to go to the login page, I need to create a button and trigger it from there.

import React from “react”;  
import { useAuth0 } from “@auth0/auth0-react”;

const LoginButton = () =\> {  
const { loginWithRedirect } = useAuth0();

return \<button onClick={() =\> loginWithRedirect()}\>Log In;  
};

export default LoginButton;

Instead of doing it on button press, is it possible to go to login page when the website is loaded first time and no one else is currently login?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 15, 2022, 11:33pm UTC](https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881/3 "2022-03-15T23:33:01Z")

</div>

Hi @msuguitan,

I tried this and it seems to work without requiring a button press:

```auto
if (!isAuthenticated) {
    loginWithRedirect();
}

```

Depending on how you are setting up your app, you may want to return a loading component or something so your page doesn’t render for a moment.

---

<div class="post-metadata">

**Author:** ![msuguitan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/msuguitan/32/14222_2.png) [@msuguitan](https://community.auth0.com/u/msuguitan)\
**Post date:** [March 17, 2022, 1:01am UTC](https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881/4 "2022-03-17T01:01:34Z")

</div>

Hi @dan.woda,

I tried this and one enclosed in a useEffect pattern, but after successfully logging in the entire app will go into a loop. Please see screenshot below.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/3/6/36eeda0492efd63a0870c14f98fb62a5ffb8adda.png)

The authorize?audience keeps on replying cancelled over and over.  
The app is not showing.  
Is there a reason for the authorize?audience to loop and be cancelled.?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 17, 2022, 3:31pm UTC](https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881/5 "2022-03-17T15:31:59Z")

</div>

Can you share your code?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 22, 2022, 12:01am UTC](https://community.auth0.com/t/go-to-login-page-without-pressing-a-button/79881/6 "2022-04-22T00:01:56Z")

</div>


