I have found a great article adding authentication into react. Article: https://www.robinwieruch.de/complete-firebase-authentication-react-tutorial/
This article finishes the firebase setup (before redux) with a HOC component that I can put into the app and can access with context.
My issue is how do i put this into the apollo client which is outside of the app component so even with the context I cant set it. I have this same problem with redux. Only one I have found is use local storage but I would like to avoid that.
This is my apollo client in the main app component.
const client = new ApolloClient({
uri: clientUrl,
request: async operation => {
const token = How_do_i_set_this <-- ???
console.log('token in request', token)
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : ''
}
});
}
});
const App = () => (
<DashAppHolder>
<ApolloProvider client={client}>
<Provider store={store}>
<PublicRoutes history={history} />
</Provider>
</ApolloProvider>
</DashAppHolder>
);
So this my not be the best way but this is how I have it setup at the moment.
this is my apollo client setup
This is my firebase helper class I import
And lastly on the server here is my graphql setup relevent information I use
This answer works and gets me the UID of the user authorized through firebase and looks like there is no delay at all. This might not be the best answer because I Put this together from several documents when I was just learning everything and have been meaning to go back and revisit when I have time but again, working.