File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 33 */
44
55import { auth } from "@project/auth" ;
6+ import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants" ;
67import { middleware } from "@src/middleware" ;
78import { NextRequest } from "next/server" ;
89
@@ -26,7 +27,7 @@ describe("middleware", () => {
2627 jest . clearAllMocks ( ) ;
2728 } ) ;
2829
29- it ( "redirects users without active session to sso-failure page" , async ( ) => {
30+ it ( "redirects users without active session to session-logout page" , async ( ) => {
3031 const testUrl = "https://testurl/abc" ;
3132 const mockRequest = getMockRequest ( testUrl ) ;
3233
@@ -36,7 +37,7 @@ describe("middleware", () => {
3637
3738 expect ( result . status ) . toBe ( 307 ) ;
3839 expect ( result . headers . get ( "Location" ) ) . toEqual (
39- `${ mockRequest . nextUrl . origin } /sso-failure?error=No%20active%20session%20found ` ,
40+ `${ mockRequest . nextUrl . origin } ${ SESSION_LOGOUT_ROUTE } ` ,
4041 ) ;
4142 } ) ;
4243
Original file line number Diff line number Diff line change 11import { auth } from "@project/auth" ;
2+ import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants" ;
23import { Session } from "next-auth" ;
34import { NextRequest , NextResponse } from "next/server" ;
45import { logger } from "@src/utils/logger" ;
@@ -9,12 +10,10 @@ const log: Logger = logger.child({ name: "middleware" });
910export async function middleware ( request : NextRequest ) {
1011 log . info ( `Inspecting ${ request . nextUrl } ` ) ;
1112 const session : Session | null = await auth ( ) ;
12- if ( ! session ?. user ?. birthdate ) {
13- return NextResponse . redirect (
14- new URL ( `/sso-failure?error=No active session found` , request . url ) ,
15- ) ;
16- }
1713 log . info ( session , "Session Object" ) ;
14+ if ( ! session ?. user ) {
15+ return NextResponse . redirect ( new URL ( SESSION_LOGOUT_ROUTE , request . url ) ) ;
16+ }
1817 return NextResponse . next ( ) ;
1918}
2019
You can’t perform that action at this time.
0 commit comments