I’m using apollo server, Auth0 and jwt/jwksClient for my app authentication.
When I look at the token my front end is sending to the back-end it has 2 dots inside which indicates its only signed. When decrypting in the back-end, jwt tells me the token is malformed.
I don’t know why its giving me this result. Any help?
Token:
eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9kZXYteWpkczdzMHcudXMuYXV0aDAuY29tLyJ9..-If5niecxqNWV7WB.VDV1LEr9TUkijSNg9-lN7trsW1ymaFxSOcVB6uDPFBofjtAF_cDXPzwg1Q7d0RtfIi6nXzwNExsd9TNyyW4dOmPYlrdrd80NYGeof7VuPxU0RdItqjj3gydAGodY_C3iT10EekryAzuETF-O8BSBf4aS7NPISHC34TJYg_dTw4ZwaQBj_ry0fCn2RFTBU8yQlEFf7DxrS0TCC3P4FMDys6JDEyKm3_2UuAyTHBY0ZZLB_5qpEmAZRH5mcs5KSnlYPd-QjrHHLCEFAq860rUyYV3HgXCm1zd_9ELX6z5ODdrQaSKBKHLxsu4iLxXDXk4Ec4U.0AGGCtcmx4KOYrJsKwAEpw
Front end code:
import { ApolloClient, InMemoryCache, ApolloProvider, HttpLink } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { useAuth0 } from '@auth0/auth0-react';
import { config } from '../../env';
function ApolloWrapper({ children }) {
const { isAuthenticated, getAccessTokenSilently } = useAuth0();
const [bearerToken, setBearerToken] = useState('');
useEffect(() => {
const getToken = async () => {
try {
const token = isAuthenticated ? await getAccessTokenSilently() : '';
setBearerToken(token);
console.log(token);
} catch (err) {
console.log('Failed to fetch token', err);
}
};
if (isAuthenticated) {
getToken();
} else {
setBearerToken('');
}
}, [getAccessTokenSilently, isAuthenticated]);
const httpLink = new HttpLink({ uri: config.GRAPHQL_URI });
const authLink = setContext((_, { headers, ...rest }) => {
if (!bearerToken) return { headers, ...rest };
return {
...rest,
headers: {
...headers,
authorization: `Bearer ${bearerToken}`,
},
};
});
const client = new ApolloClient({
cache: new InMemoryCache(),
link: authLink.concat(httpLink),
});
return <ApolloProvider client={client}>{children}</ApolloProvider>;
}
export default ApolloWrapper;