gatsby-theme-auth0 icon indicating copy to clipboard operation
gatsby-theme-auth0 copied to clipboard

reject if checkSession returned error

Open dandv opened this issue 5 years ago • 4 comments

This PR makes checkSession explicitly reject after removing the local session, if auth0.checkSession returned an error. Previously, the developer had to check localStorage for isLoggedIn, because checkSession would always resolve.

dandv avatar May 24 '20 04:05 dandv

Deploy request for gatsby-theme-auth0-custom pending review.

Review with commit b924f07af80bc2d2b9d890008e17d5d94d6b6c45

https://app.netlify.com/sites/gatsby-theme-auth0-custom/deploys

netlify[bot] avatar May 24 '20 04:05 netlify[bot]

Deploy request for gatsby-theme-auth0 pending review.

Review with commit b924f07af80bc2d2b9d890008e17d5d94d6b6c45

https://app.netlify.com/sites/gatsby-theme-auth0/deploys

netlify[bot] avatar May 24 '20 04:05 netlify[bot]

Hey @dandv, thanks for contributing!

This looks like a reasonable change. Do you know if there are any caveats to this? i.e. could this break existing usage?

With this change, should we move auth.checkSession() into the try catch block? https://github.com/epilande/gatsby-theme-auth0/blob/525ce267c0694dcba0ba806422a68b52c0aa9290/gatsby-theme-auth0/src/hooks/useAuth.ts#L17-L23

epilande avatar May 26 '20 20:05 epilande

Hey @epilande, I realized my reject() call was missing the err parameter. Fixed that.

How I realized that was by noticing that my apollo-client retry code was failing when the JWT had expired. I reverted to the original gatsby-theme-auth0 (without my patch), and the error was clear: apollo-client was expecting the checkSession() promise to reject, vs. return undefined. More about that in https://github.com/apollographql/apollo-client/issues/6414. So for this use case I do need checkSession() to reject(err) on error.

Not sure about other caveats. I've been using this since I proposed the PR without any negative impact I could notice.

Re. moving auth.checkSession() into the catch block, that makes sense. Something else I did notice on one occasion, most likely due to an expired JTW, was that { isLoggedIn, profile} = useAuth() returned true for isLoggedIn, and undefined for profile. Do you think this move might solve that?

dandv avatar Jun 09 '20 00:06 dandv