feat: add refresh token capability
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import generateAuthUrl from './generate-auth-url';
|
import generateAuthUrl from './generate-auth-url';
|
||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified';
|
||||||
|
import refreshAccessToken from './refresh-access-token';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
@@ -61,6 +62,7 @@ export default {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
|
refreshAccessToken,
|
||||||
generateAuthUrl,
|
generateAuthUrl,
|
||||||
verifyCredentials,
|
verifyCredentials,
|
||||||
isStillVerified,
|
isStillVerified,
|
||||||
|
@@ -39,7 +39,25 @@ export default function createHttpClient({
|
|||||||
|
|
||||||
instance.interceptors.response.use(
|
instance.interceptors.response.use(
|
||||||
(response) => response,
|
(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);
|
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 {
|
export interface IAuth {
|
||||||
generateAuthUrl?($: IGlobalVariable): Promise<void>;
|
generateAuthUrl?($: IGlobalVariable): Promise<void>;
|
||||||
verifyCredentials($: IGlobalVariable): Promise<any>;
|
verifyCredentials($: IGlobalVariable): Promise<void>;
|
||||||
isStillVerified($: IGlobalVariable): Promise<boolean>;
|
isStillVerified($: IGlobalVariable): Promise<boolean>;
|
||||||
|
refreshAccessToken?($: IGlobalVariable): Promise<void>;
|
||||||
fields: IField[];
|
fields: IField[];
|
||||||
authenticationSteps?: IAuthenticationStep[];
|
authenticationSteps?: IAuthenticationStep[];
|
||||||
reconnectionSteps?: IAuthenticationStep[];
|
reconnectionSteps?: IAuthenticationStep[];
|
||||||
|
Reference in New Issue
Block a user