Skip to content

Commit

Permalink
feat(middleware): allow url as promise function
Browse files Browse the repository at this point in the history
  • Loading branch information
glebcha committed Nov 29, 2023
1 parent bf006c1 commit 88a24bb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/middleware/auth/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export function initAuthMiddleware(initParams: AuthMiddlewareParams) {
getHeaders,
handleAuthError,
} = initParams;
const sanitizedUrl = typeof url === 'function' ? url() : url;

return async (...params: Parameters<MiddlewareHandler>) => {
const [options, meta] = params;
const currentSessionTokens = getTokens();
const sanitizedUrl = typeof url === 'function' ? await url() : url;
const headers =
typeof getHeaders === 'function' ?
getHeaders(meta) :
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/auth/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface AuthMiddlewareParams {
url: string | (() => string);
url: string | (() => Promise<string>);
method?: RequestInit['method'];
errorCodes?: Response['status'][];
getTokens: (tokens?: unknown) => { accessToken: string; refreshToken: string };
Expand Down

0 comments on commit 88a24bb

Please sign in to comment.