r/graphql • • Feb 21 '20

Authentication with Apollo Client?

Could someone look into this? I was unable to copy paste properly formatted code here

https://stackoverflow.com/questions/60346591/graphql-authentication-with-react-typescript

0 Upvotes

1 comment sorted by

10

u/danielrearden Feb 21 '20 edited Feb 22 '20

You need to call your mutation using the useMutation hook or the Mutation component, await the result of the mutation, use the result to set the value of token in local storage and then either trigger a refetch of the relevant queries or call client.resetStore.

However, there's a number of other things off about your code (using string interpolation instead of variables, embedding the client directly inside your component). Based on that and the previous question you asked on SO, I would suggest starting smaller and working through Apollo's extensive documentation and examples, beginning with this.