auth0 / auth0-react

Auth0 SDK for React Single Page Applications (SPA)
MIT License
891 stars 259 forks source link

useEffect runs twice when isAuthenticated returns True #788

Closed AsuraKev closed 3 months ago

AsuraKev commented 3 months ago

Checklist

Description

Hi there,

I have a react app with Auth0 react SDK. In my scenario, I set a returnTo in the cookie and when auth0 redirects user back to the app from the login, the app can restore back to the original application url. However I notice that when auth0 redirected back to app the isAuthenticated flag went from False, True, True.

The question is to why the useEffect runs twice for the same isAuthenticated value which is true?

image

Reproduction

create a useEffect and put isAuthenticated as a dependency. Trigger a login and redirect you ll see that useEffect is triggered twice for the same value.

Additional context

No response

auth0-react version

2.2.4

React version

18.3.1

Which browsers have you tested in?

Chrome