Fetch jwt token from hasura-auth with refresh_token

This commit is contained in:
Charles Bochet
2023-04-21 14:07:02 +02:00
parent f98f0e942e
commit c5f2850a3b
26 changed files with 212 additions and 61 deletions

32
front/src/apollo.tsx Normal file
View File

@ -0,0 +1,32 @@
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { RestLink } from 'apollo-link-rest';
const apiLink = createHttpLink({
uri: `${process.env.REACT_APP_API_URL}/v1/graphql`,
});
const withAuthHeadersLink = setContext((_, { headers }) => {
const token = localStorage.getItem('accessToken');
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
};
});
export const apiClient = new ApolloClient({
link: withAuthHeadersLink.concat(apiLink),
cache: new InMemoryCache(),
});
const authLink = new RestLink({
uri: `${process.env.REACT_APP_AUTH_URL}`,
credentials: 'same-origin',
});
export const authClient = new ApolloClient({
link: authLink,
cache: new InMemoryCache(),
});