-
-
Notifications
You must be signed in to change notification settings - Fork 414
Closed
Description
Hi, Could you change template code so that securityWorker will be async function. I need this so that I can check my JWT token is expired or not and update it if it is expired. I can not do this with current securityWorker.
I suggest you to change current template to below
type ApiConfig<SecurityDataType> = {
baseUrl?: string;
baseApiParams?: RequestParams;
securityWorker?: (securityData: SecurityDataType) => Promise<RequestParams>;
};
public request = async <T = any, E = any>(
path: string,
method: string,
{ secure, ...params }: RequestParams = {},
body?: any,
bodyType?: BodyType,
secureByDefault?: boolean,
): Promise<T> =>{
const securityRequestParams = (secureByDefault || secure) && (await this.securityWorker(this.securityData));
return fetch(`${this.baseUrl}${path}`, {
// @ts-ignore
...this.mergeRequestOptions(params, securityRequestParams),
method,
body: body ? this.bodyFormatters[bodyType || BodyType.Json](body) : null,
}).then(async (response) => {
const data = await this.safeParseResponse<T, E>(response);
if (!response.ok) throw data;
return data;
});
}
Metadata
Metadata
Assignees
Labels
No labels