feat: add refresh token capability
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import refreshAccessToken from './refresh-access-token';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
@@ -61,6 +62,7 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
refreshAccessToken,
|
||||
generateAuthUrl,
|
||||
verifyCredentials,
|
||||
isStillVerified,
|
||||
|
@@ -39,7 +39,25 @@ export default function createHttpClient({
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
async (error) => {
|
||||
const { config } = error;
|
||||
const { status } = error.response;
|
||||
|
||||
if (status === 401 && $.app.auth.refreshAccessToken && config.additionalProperties.shouldRetry !== false) {
|
||||
await $.app.auth.refreshAccessToken($);
|
||||
|
||||
// retry the request
|
||||
const newResponse = await instance.request({
|
||||
...config,
|
||||
additionalProperties: {
|
||||
...(config.additionalProperties || {}),
|
||||
shouldRetry: false,
|
||||
}
|
||||
});
|
||||
|
||||
return newResponse;
|
||||
}
|
||||
|
||||
throw new HttpError(error);
|
||||
}
|
||||
);
|
||||
|
3
packages/types/index.d.ts
vendored
3
packages/types/index.d.ts
vendored
@@ -179,8 +179,9 @@ export interface IDynamicData {
|
||||
|
||||
export interface IAuth {
|
||||
generateAuthUrl?($: IGlobalVariable): Promise<void>;
|
||||
verifyCredentials($: IGlobalVariable): Promise<any>;
|
||||
verifyCredentials($: IGlobalVariable): Promise<void>;
|
||||
isStillVerified($: IGlobalVariable): Promise<boolean>;
|
||||
refreshAccessToken?($: IGlobalVariable): Promise<void>;
|
||||
fields: IField[];
|
||||
authenticationSteps?: IAuthenticationStep[];
|
||||
reconnectionSteps?: IAuthenticationStep[];
|
||||
|
Reference in New Issue
Block a user