Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No requests are made if applyAuthTokenInterceptor called #60

Open
marisancans opened this issue May 1, 2023 · 1 comment
Open

No requests are made if applyAuthTokenInterceptor called #60

marisancans opened this issue May 1, 2023 · 1 comment

Comments

@marisancans
Copy link

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")
@marisancans
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant