react-netlify-identity icon indicating copy to clipboard operation
react-netlify-identity copied to clipboard

How to integrate with apollo client?

Open brielov opened this issue 4 years ago • 1 comments

I have a simple graphql netlify function and I would like to integrate react-netlify-identity. Is there a built in method I can use? Or some other way around?

brielov avatar May 22 '20 20:05 brielov

@brielov I'm not sure you're still in search of an answer to this question, but these resources might help provide some context:

  • https://docs.netlify.com/functions/functions-and-identity/
  • https://www.apollographql.com/docs/react/networking/authentication/#header

If your Apollo Client is pointing to your .netlify/functions GraphQL URI. You can include the logged in user's JWT in the Authorization header of your request (or perhaps when the ApolloClient is instantiated). You can access the user in your React code with this library through the useIdentityContext hook.

If a Netlify function is called with a valid identity JWT you should be able to access the user information from the context parameter of your Netlify functions.

export function(event, context, callback) {
  const { identity, user } = context.clientContext;
}

elijahsullivan avatar Aug 20 '20 01:08 elijahsullivan