Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix: refresh-token

kruzhambus159decbe5050
diff --git a/package.json b/package.json
index ea1a5302d..0bd48f938 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"@heroicons/react": "^2.0.13",
"@swetrix/sdk": "^1.0.0",
"@tailwindcss/forms": "^0.5.3",
- "axios": "^1.2.2",
+ "axios": "^1.3.2",
"axios-auth-refresh": "^3.3.6",
"billboard.js": "^3.6.3",
"clsx": "^1.2.1",
diff --git a/src/api/index.js b/src/api/index.js
index 0dc0de6a9..f60a41562 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -22,9 +22,9 @@ const api = axios.create({
// Function that will be called to refresh authorization
const refreshAuthLogic = (failedRequest) =>
axios
- .post(`${baseURL}/v1/auth/refresh-token`, null, {
+ .post(`${baseURL}v1/auth/refresh-token`, null, {
headers: {
- Authorization: `Bearer ${getRefreshToken}`,
+ Authorization: `Bearer ${getRefreshToken()}`,
},
})
.then((tokenRefreshResponse) => {
@@ -34,6 +34,12 @@ const refreshAuthLogic = (failedRequest) =>
failedRequest.response.config.headers.Authorization = `Bearer ${accessToken}`
return Promise.resolve()
})
+ .catch((error) => {
+ removeAccessToken()
+ removeRefreshToken()
+ store.dispatch(authActions.logout())
+ return Promise.reject(error)
+ })
// Instantiate the interceptor
createAuthRefreshInterceptor(api, refreshAuthLogic)
@@ -52,18 +58,6 @@ api.interceptors.request.use(
},
)
-api.interceptors.response.use(
- (response) => response,
- (error) => {
- if (error.response?.data.statusCode === 401) {
- removeAccessToken()
- removeRefreshToken()
- store.dispatch(authActions.logout())
- }
- return Promise.reject(error)
- },
-)
-
export const authMe = () =>
api
.get('user/me')