Skip to content

Commit 2d5c010

Browse files
committed
CCM-5340: use NextRequest and add content type
1 parent 1eb69b7 commit 2d5c010

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

frontend/src/__tests__/middleware.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ describe('middleware function', () => {
2525
const request = new NextRequest(url);
2626
const response = await middleware(request);
2727

28-
expect(response.status).toBe(302);
28+
expect(response.status).toBe(307);
2929
expect(response.headers.get('location')).toBe(
3030
'https://url.com/auth?redirect=%2Ftemplates%2F%2Fmanage-templates'
3131
);
32+
expect(response.headers.get('Content-Type')).toBe('text/html');
3233
});
3334

3435
it('if request path is protected, and access token is obtained, respond with CSP', async () => {

frontend/src/middleware.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ export async function middleware(request: NextRequest) {
5757
const token = await getAccessTokenServer();
5858

5959
if (!token) {
60-
return Response.redirect(
60+
const redirectResponse = NextResponse.redirect(
6161
new URL(
6262
`/auth?redirect=${encodeURIComponent(
6363
`${getBasePath()}/${request.nextUrl.pathname}`
6464
)}`,
6565
request.url
6666
)
6767
);
68+
69+
redirectResponse.headers.set('Content-Type', 'text/html');
70+
71+
return redirectResponse;
6872
}
6973

7074
const response = NextResponse.next({

0 commit comments

Comments
 (0)