File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,12 @@ export async function middleware(req: NextRequest) {
17
17
18
18
// OPTIONAL: this forces users to be logged in to use the chatbot.
19
19
// If you want to allow anonymous users, simply remove the check below.
20
- if ( ! session && ! req . url . includes ( '/sign-in' ) )
21
- return NextResponse . redirect ( new URL ( '/sign-in' , req . url ) )
20
+ if ( ! session && ! req . url . includes ( '/sign-in' ) ) {
21
+ const redirectUrl = req . nextUrl . clone ( )
22
+ redirectUrl . pathname = '/sign-in'
23
+ redirectUrl . searchParams . set ( `redirectedFrom` , req . nextUrl . pathname )
24
+ return NextResponse . redirect ( redirectUrl )
25
+ }
22
26
23
27
return res
24
28
}
@@ -27,11 +31,12 @@ export const config = {
27
31
matcher : [
28
32
/*
29
33
* Match all request paths except for the ones starting with:
34
+ * - share (publicly shared chats)
30
35
* - api (API routes)
31
36
* - _next/static (static files)
32
37
* - _next/image (image optimization files)
33
38
* - favicon.ico (favicon file)
34
39
*/
35
- '/((?!api|_next/static|_next/image|favicon.ico).*)'
40
+ '/((?!share| api|_next/static|_next/image|favicon.ico).*)'
36
41
]
37
42
}
You can’t perform that action at this time.
0 commit comments