fix(auth): guard temporary token refresh and translate bill flow
This commit is contained in:
1 parent
2b467dc076
commit
3f015d8e22
12 files changed
+238
-20
No files matched your search
@@ -9,6 +9,8 @@ export interface CreateAuthClientOptions {
|
||||
prefixUrl: string;
|
||||
getHeaders: () => Promise<Record<string, string>> | Record<string, string>;
|
||||
onUnauthorized?: () => Promise<void> | void;
|
||||
onAuthFailure?: (response: Response) => Error;
|
||||
retryUnauthorized?: boolean;
|
||||
}
|
||||
|
||||
export function createClient(options: CreateClientOptions): KyInstance {
|
||||
@@ -22,7 +24,7 @@ export function createAuthClient(options: CreateAuthClientOptions): KyInstance {
|
||||
return ky.create({
|
||||
prefix: options.prefixUrl,
|
||||
retry: {
|
||||
limit: 1,
|
||||
limit: options.retryUnauthorized === false ? 0 : 1,
|
||||
methods: ["get", "post", "put", "delete", "patch"],
|
||||
statusCodes: [401],
|
||||
},
|
||||
@@ -59,6 +61,9 @@ export function createAuthClient(options: CreateAuthClientOptions): KyInstance {
|
||||
}
|
||||
return ky(request);
|
||||
}
|
||||
if (isAuthError && options.onAuthFailure) {
|
||||
throw options.onAuthFailure(response);
|
||||
}
|
||||
return response;
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user