Double login using Javascript SDK

Hi,

I’ve implemented the quickstart for JS at:
https://auth0.com/docs/quickstart/spa/vanillajs#integrate-auth0-in-your-application

Having integrated into our app I was not able to get it to work as is.
I have investigated it thoroughly. What happens is that at the point in time the application calls webAuth.parseHash the authResult is still null so the code fails. If you click login again, it will work.

I was able to work around it by delaying the call to the authorize function by 5 seconds (less than that gives unreliable results - sometimes works sometimes doesn’t). However this wasn’t really satisfactory.

Strangely, I could also get around it by instead console.logging window.location.hash prior to calling webAuth.parseHash. I suspect this provides just enough of some sort of delay.

As I don’t want that console.log there I am achieving the same by checking window.location.hash prior to calling it:

if(window.location.hash !== "") {
  webAuth.parseHash(... parse function ...);
}

I would like to move to calling the parseHash on loading the page rather than having a login button - by using window.onload = webAuth.authorize.

My solution 1 allows for that to work but does anyone have a proper solution, as it seems wrong to rely on a setTimout to make it all work and it does introduce quite a delay.
My solution 2 seems doesn’t work in that scenario, probably because it doesn’t delay things enough - it seems dodgy anyway.

Hey there!

Sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes the number of incoming questions is just too big for our bandwidth. Sorry for such inconvenience!

Do you still require further assistance from us?