I have been banging my head against the wall trying to figure this out. It should be so simple and yet I can’t figure out what’s wrong.
const useRefreshToken = () => {
const { setAuth } = useAuth();
const refresh = async () => {
try {
const response = await axios.get('/refresh', {
withCredentials: true,
});
console.log(response.data);
setAuth(response.data); // ! Problem
return response.data;
} catch (err) {
console.error(err);
}
};
return refresh;
};
My refresh function should be using the user’s refresh token to generate a new accessToken, then it will save that accessToken to my auth state with setAuth.
I use setAuth and auth in multiple components in my code base and it works just fine. But now however I am getting
TypeError: setAuth is not a function
My hope was that setAuth would simply add the accessToken to the auth state and that would be it.
setAuth takes an object which is what response.data is returning.
I have tried multiple different ways of using setAuth, and I am unsure what to focus on next.
1