react-netlify-identity-gotrue

react-netlify-identity-gotrue is an open source JavaScript package available on npm. It provides a pure-React integration between React-based apps (including SSGs like Gatsby and Next.js) and Netlify Identity. Differing from Netlify Identity stacks that leverage gotrue-js under the hood, this library is written entirely in async hooks-based React and interfaces directly with the GoTrue service that runs Netlify Identity.

One of the stronger points of this library is its innate ability to keep a user’s JWT fresh (refreshed / unexpired) without any management by the consuming application. react-netlify-identity-gotrue ensures that the user’s JWT is always available for authorized calls and checks. It even includes an authorizedFetch() function out-of-the-box for making just such calls. This makes working with Functions, which become super powerful when Netlify Identity is activated on a site, that much easier.

Feel free to check out the demo application, a fully-integrated Gatsby app that displays the depth of ability from react-netlify-identity-gotrue — email-based workflows fully implemented, private routing included, and authorizedFetch()’s to boot!

// Usage example
identity.authorizedFetch('/api/update-role', {
  method: 'POST',
  body: JSON.stringify({
    action: add ? 'add' : 'remove',
      role: add || remove
    })
  })
  .then(resp => resp.json())
  .then(token => console.log(token.status))

You can also check out my announcement post here