Navigate the user directly to the login page if not authenticated

Wondering how to go to the login page without pressing a button. In the examples, the button is always provided and you have to trigger loginWithRedirect() by clicking a button.

This issue is still valid.

The code below leads to an infinite loop.

if (!isAuthenticated) {
    loginWithRedirect();
}

My code:

import React from 'react'
import { App } from './views/App'
import { useAuth0 } from '@auth0/auth0-react'

export const App = () => {
  const { loginWithRedirect, isAuthenticated } = useAuth0()

  if (!isAuthenticated) {
    loginWithRedirect()
  }

  return <App />
}

Hi @Maikki,

Did you ever resolve this issue? I am having the same problem and curious what you did to get around this.