-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
withAuthenticationRequired invokes loginWithRedirect multiple times #309
Comments
Hi @kweiberth - thanks for raising this
I'd be happy to debug what's happening with your app, if you can provide me with a repo that demonstrates the issue. |
Hi @adamjmcgrath, thanks for the quick response. I'll see if I can get a repo together. In the meantime, can you describe a little more why we are so certain that From what I can tell, it's being invoked inside a |
@adamjmcgrath I've created a repo that reproduces this issue: https://github.com/kweiberth/multiple-Auth0-logins. State is set in Let me know if you need any more information! |
Thanks for sharing the repo @kweiberth
You make a good point - I'll take a look at this today or tomorrow and get back to you. |
@kweiberth - I've had a look at your repo and while I think there's some merit to your suggestion about login options (or something similar). I'll add something to our backlog, but this will probably have to wait until the new year. As an aside, you're also creating a new instance of |
Hi @adamjmcgrath, thanks for looking into it. Will it help if I make a PR? It's a pretty simple change. Edit: just saw the link to the change you made. 👍 No worry on timing... I've pulled this logic out into my app for now, and whenever it gets released I can migrate back to official library. Re: instances on each route: I'm doing this bc auth0 JS SPA is a huge bundle size (like 40kb I think?), so I can't add it to every route. There are profile-type pages on our site that need to load as fast as possible, and don't require auth. I've been meaning to see if I can lazy load it w/ Next.js's dynamic imports, but haven't had a chance to explore. |
Sure - happy to look at a PR @kweiberth thanks. But either way, it wont get released until shortly after the beginning of January
Ok, I would just make sure that https://github.com/kweiberth/multiple-Auth0-logins/blob/master/utils/with-auth0.tsx#L104 doesn't get invoked more than once per page load |
Okay yeah, makes sense. I don't think it is, but I guess it could be happening transiently/inconsistently to my users (similar to this one that we're discussing/fixing here). I've made a PR to address this issue: #311 |
* Avoid potential multiple invocations of loginWithRedirect Resolves #309 * add test to assert single call * remove comment
* Avoid potential multiple invocations of loginWithRedirect Resolves auth0/auth0-react#309 * add test to assert single call * remove comment
* Avoid potential multiple invocations of loginWithRedirect Resolves auth0/auth0-react#309 * add test to assert single call * remove comment
* Avoid potential multiple invocations of loginWithRedirect Resolves auth0/auth0-react#309 * add test to assert single call * remove comment
* Avoid potential multiple invocations of loginWithRedirect Resolves auth0/auth0-react#309 * add test to assert single call * remove comment
Explanation:
loginWithRedirect()
.withAuthenticationRequired
method from@auth0/auth0-react
. To help myself debug, I pulled out this method into my own application so I could debug/log stuff. I realized that the useEffect here is being invoked multiple times, and the culprit isloginOptions
as a dependency. I'm not passing inloginOptions
, so it seems that on each render we're defaulting it to a new instance of an empty object (here), and this is triggering the useEffect (bc they are different empty objects and they are!==
).const emptyObject = {}
and then used it as the default:loginOptions = emptyObject
.Expected behavior:
loginWithRedirect
only once.Reproduction:
Environment:
auth0-react
used: 1.8.0The text was updated successfully, but these errors were encountered: