axios-jwt
axios-jwt copied to clipboard
No requests are made if applyAuthTokenInterceptor called
Hello, im using React 18 and axios 1.4.0 This is how I define the axios instance (following the tutorial)
const BASE_URL = 'http://localhost:8080/api'
// 1. Create an axios instance that you wish to apply the interceptor to
export const apiAuthInstance = axios.create({ baseURL: BASE_URL })
// 2. Define token refresh function.
const requestRefresh: TokenRefreshRequest = async (refreshToken: string): Promise<IAuthTokens | string> => {
const response = await axios.post(`${BASE_URL}/auth/refresh_token`, { token: refreshToken })
return response.data.access_token
}
// 3. Add interceptor to your axios instance
applyAuthTokenInterceptor(apiAuthInstance, { requestRefresh })
// If applyAuthTokenInterceptor is applied, then I cant make any api calls at all
// Here "/asd" wont be called, or any other place it just doesnt make the call.
// What am I doing wrong?
apiAuthInstance.post("/asd")
Im getting an error in console:
Unable to refresh access token for request due to token refresh error: Invalid token specified: undefined
Howerver, if I manually call:
console.log(getAccessToken())
console.log(getRefreshToken())
I see that these tokens are available to me and are in local storage