use-auth0-hooks icon indicating copy to clipboard operation
use-auth0-hooks copied to clipboard

On page load, if not logged in, isLoading is always true

Open benheb opened this issue 5 years ago • 12 comments

Everything is working wonderfully, except... when I load my app without a user logged in, and am checking for isLoading, it gets set to true but never gets set to false. With a logged in user on a fresh page load it works as expected –– is true while setting the session, then is set to false.

It's crucial to be able to check isLoading even when a user is not logged in. To me it makes sense that on initialization it's set to true, but once it's determined the user is not in fact logged in or logging in, it should be set to false.

benheb avatar Dec 29 '19 04:12 benheb

+1 I'm also seeing this.

icco avatar Jan 05 '20 19:01 icco

@icco have you had any luck here? May pull it down again and try and get it working locally to see what's up. I had issues doing that at first try because it's typescript and my app isn't (or something along those lines). It seems even when logged in, the isLoading flag is not reliably set to false when everything is complete.

benheb avatar Jan 09 '20 04:01 benheb

So I finally got this working last night. My logic is at https://github.com/icco/writing/blob/master/lib/auth.js. also check out pages/_app.js and components/Header.js

icco avatar Jan 09 '20 14:01 icco

@icco thanks! I'm not using graphql/apollo so will have to sort through some of the magic you're using with lazy query... but I think the idea makes sense? Thanks for sharing.

benheb avatar Jan 10 '20 04:01 benheb

I'm observing both behaviors described here when audience and scope are provided to useAuth:

  • isLoading sometimes remains true when logged in and the access token is fetched
  • isLoading stays true when logged out

@sandrinodimattia is this intentional behavior or a bug?

derrickreimer avatar Mar 16 '20 15:03 derrickreimer

I'm having exactly the same behavior as you @derrickreimer, isLoading behaves erratically.

I think that @sandrinodimattia has abandoned this repo, the latest commit was on December 5th.

I'm using @msembinelli's fork (https://github.com/msembinelli/use-auth0-hooks) that fixes #22 and seems to be actively maintained.

We could try to resolve the issue on his repo and kind of make it the de-facto fork.

What do you think guys?

ngirardin avatar Apr 21 '20 14:04 ngirardin

Hi @ngirardin I am already thinking about making an official package for mine under a new name, I will keep you updated. Does the isLoading work for you on my fork?

I am willing to get this fixed and maintain it on mine as I am actively consuming it for a project.

Edit: looking into this and hope to have a fix in the next couple of days Edit2: I can no longer product this bug, can someone verify if this issue still persists on my fork?

msembinelli avatar Apr 21 '20 18:04 msembinelli

Hi @msembinelli, sorry for the late reply!

I'll be actively working on integrating Auth0 on our app for the next days, I'm gonna test your fork (https://github.com/msembinelli/use-auth0-hooks) and keep you updated here.

ngirardin avatar May 08 '20 14:05 ngirardin

Hi @msembinelli, I'm using your fork for a few days and the isLoading behavior is better.

It works when the user is not authenticated, and when the page is called by the Auth0 callback, but once the user is authenticated, isLoading is always true.

ngirardin avatar May 14 '20 13:05 ngirardin

@ngirardin I'm not seeing this occur on my end. When user gets set, isLoading should be toggled. I might have to dig into this one a bit more. Is there anything you can provide as far as examples snippets and logs go?

msembinelli avatar May 15 '20 16:05 msembinelli

@msembinelli I think that my cache was in a weird state, I cleared it and it worked

ngirardin avatar May 20 '20 11:05 ngirardin

All of the concepts of this library have been moved to the official Auth0 SDK for React (https://github.com/auth0/auth0-react), so I'll be archiving this repository shortly.

sandrinodimattia avatar Jun 23 '20 12:06 sandrinodimattia