|
|
@ -1,6 +1,8 @@ |
|
|
|
import type { Api } from 'nocodb-sdk' |
|
|
|
import type { Api } from 'nocodb-sdk' |
|
|
|
const DbNotFoundMsg = 'Database config not found' |
|
|
|
const DbNotFoundMsg = 'Database config not found' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TIMEOUT_RETRY_COUNT = 1 |
|
|
|
|
|
|
|
|
|
|
|
export function addAxiosInterceptors(api: Api<any>) { |
|
|
|
export function addAxiosInterceptors(api: Api<any>) { |
|
|
|
const state = useGlobal() |
|
|
|
const state = useGlobal() |
|
|
|
const router = useRouter() |
|
|
|
const router = useRouter() |
|
|
@ -61,37 +63,44 @@ export function addAxiosInterceptors(api: Api<any>) { |
|
|
|
return Promise.reject(error) |
|
|
|
return Promise.reject(error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
let retry = 0 |
|
|
|
const token = await state.refreshToken({ |
|
|
|
do { |
|
|
|
axiosInstance, |
|
|
|
try { |
|
|
|
skipLogout: true, |
|
|
|
const token = await state.refreshToken({ |
|
|
|
}) |
|
|
|
axiosInstance, |
|
|
|
|
|
|
|
skipLogout: true, |
|
|
|
if (!token) { |
|
|
|
|
|
|
|
await state.signOut({ |
|
|
|
|
|
|
|
redirectToSignin: !isSharedPage, |
|
|
|
|
|
|
|
skipApiCall: true, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
return Promise.reject(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const config = error.config |
|
|
|
|
|
|
|
config.headers['xc-auth'] = token |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await axiosInstance.request(config) |
|
|
|
if (!token) { |
|
|
|
return response |
|
|
|
await state.signOut({ |
|
|
|
} catch (refreshTokenError) { |
|
|
|
redirectToSignin: !isSharedPage, |
|
|
|
if ((refreshTokenError as any)?.code === 'ERR_CANCELED') { |
|
|
|
skipApiCall: true, |
|
|
|
return Promise.reject(refreshTokenError) |
|
|
|
}) |
|
|
|
|
|
|
|
return Promise.reject(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const config = error.config |
|
|
|
|
|
|
|
config.headers['xc-auth'] = token |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await axiosInstance.request(config) |
|
|
|
|
|
|
|
return response |
|
|
|
|
|
|
|
} catch (refreshTokenError) { |
|
|
|
|
|
|
|
if ((refreshTokenError as any)?.code === 'ERR_CANCELED') { |
|
|
|
|
|
|
|
return Promise.reject(refreshTokenError) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if shared execution error, don't sign out
|
|
|
|
|
|
|
|
if (!(refreshTokenError instanceof SharedExecutionError)) { |
|
|
|
|
|
|
|
await state.signOut({ |
|
|
|
|
|
|
|
redirectToSignin: !isSharedPage, |
|
|
|
|
|
|
|
skipApiCall: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return Promise.reject(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (retry >= TIMEOUT_RETRY_COUNT) return Promise.reject(error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} while (retry++ < TIMEOUT_RETRY_COUNT) |
|
|
|
await state.signOut({ |
|
|
|
|
|
|
|
redirectToSignin: !isSharedPage, |
|
|
|
|
|
|
|
skipApiCall: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Promise.reject(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|