netlify-labs / react-netlify-identity

a tiny (4kb) React hook for using Netlify Identity, no UI. SEEKING MAINTAINERS
https://netlify-gotrue-in-react.netlify.com/
156 stars 25 forks source link

How to integrate with apollo client? #38

Open brielov opened 4 years ago

brielov commented 4 years ago

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?

elijahsullivan commented 4 years ago

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

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;
}