Skip to content

Commit

Permalink
feat: Refactor middleware functions for better organization and clarity
Browse files Browse the repository at this point in the history
Consolidated import statements for NextRequest and NextResponse.
Added import statements for middleware functions from their respective files.
Removed unnecessary imports and constants.
Refactored middleware function for improved readability.
Added edgeLogger for logging middleware actions.
Separated handling of verify requests into a dedicated function.
Improved error handling and validation checks within middleware.
  • Loading branch information
thostetler committed Mar 24, 2024
1 parent 04aedef commit a0df82f
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 456 deletions.
6 changes: 5 additions & 1 deletion global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare module 'iron-session' {
username: string;
};
isAuthenticated?: boolean;
apiCookieHash?: number[];
apiCookieHash?: string;
bot?: boolean;
}
}
Expand Down Expand Up @@ -43,7 +43,11 @@ declare global {
NEXT_PUBLIC_GTM_ID: string;
NEXT_PUBLIC_RECAPTCHA_SITE_KEY: string;
NEXT_PUBLIC_API_MOCKING: string;
NEXT_PUBLIC_SENTRY_DSN: string;
NEXT_PUBLIC_SENTRY_PROJECT_ID: string;
GIT_SHA: string;
CSP_REPORT_URI: string;
CSP_REPORT_ONLY: string;
}
}
}
2 changes: 1 addition & 1 deletion src/api/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test('basic request calls bootstrap and adds auth', async ({ server }: TestConte
// first request was intercepted and bootstrapped
expect(urls(onReq)[0]).toEqual(API_USER);
// the refresh header was added to force a new session
expect(onReq.mock.calls[0][0].headers.get('X-RefreshToken')).toEqual('1');
expect(onReq.mock.calls[0][0].headers.get('X-Refresh-Token')).toEqual('1');

const expectedToken = (JSON.parse(onRes.mock.calls[0][0].body) as IApiUserResponse).user.access_token;

Expand Down
2 changes: 1 addition & 1 deletion src/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const hash = async (str?: string) => {
}
try {
const buffer = await globalThis.crypto.subtle.digest('SHA-1', Buffer.from(str, 'utf-8'));
return Array.from(new Uint8Array(buffer));
return Array.from(new Uint8Array(buffer)).toString();
} catch (e) {
return null;
}
Expand Down
Loading

0 comments on commit a0df82f

Please sign in to comment.