Netlify Identity oAuth

I’ve struggled for some time to get identity work with React and I still come across issues. Have a look at this deployment:
https://romantic-davinci-c26b02.netlify.com/login
repo: https://github.com/abtx/identity-widget

I assume that these should be true:

  1. widget connects to whatever APIs needs, and redirects
  2. user is available in netlifyIdentity after the redirect is complete using netlifyIdentity.currentUser()

This flow is true on Safari,

On Chrome and FF, I get this behaviour:

  1. widget connects to whatever APIs needs, and redirects
  2. netlifyIdentity.currentUser() returns null

Please help me understand why the code works differently between browsers and what’s the correct implementation.

Hey @abtx,
As far as I know, we haven’t seen other reports of different behavior on Safari vs. Chrome or FF with the Netlify Identity widget, but I can keep an eye out and post again here if I see anything. What you’re seeing could have to do with how those browsers handle React. If your users are being correctly created in the Netlify UI (you’ll be able to check here: https://app.netlify.com/sites/romantic-davinci-c26b02/identity), then the issue is likely with the code- the identity instance being referenced in a different scope than where you’re logging, how you’re doing client side routing based on that, etc.

Want to have a look at this React wrapper and see if you find it helpful? There are also some good demos in the readme:

Hi Jen, thanks for the reply. I tried the react-netlify-identity but it has its own issues and the author recommends using the netlify-identity-widget instead, which has example with React, but it doesn’t work. Does Netlify plann to fix that example or provide another working example for React?

PS: routing is done as in the example provided. netlifyIdentity it’s available on all routes. It simply redirects to /login if netlifyIdentity.currentUser() doesn’t return a user. So the netlifyIdentity has to return a user in the first place before the router decides on redirecting to private route. Which it does in Safari only. It looks like after authentication Chrome and FF fail to update the netlifyIdentity instance. Usually, go.true user is stored in local storage after authentication, which, as far as I understand, will be used to update the identity instance. Can we agree that the go.true user should be there after authentication, no matter the routing?

You’re right, that example does seem to be broken! I don’t have an update yet but wanted to let you know I’m digging into it :slight_smile:

1 Like

I thought fixing the broken example would be much more straightforward than it turned out to be, but in updating dependencies on our netlify-identity-widget React example, I seemed to just break everything even further! We are still working on it.

In the meantime, I checked in with our own @DavidWells and he shared some resources that I wanted to pass along. Maybe he (or @Dennis?) will also have some insight into why you’re seeing the behavior you are.

We’ll update this post again when we have more to share, and please let us know if you managed to find a fix!

Hi Jen, thanks for the update!