Skip to content

Commit 045b0b9

Browse files
author
thorwebdev
committed
fix: allow public access for share route.
1 parent 2052847 commit 045b0b9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

middleware.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ export async function middleware(req: NextRequest) {
1717

1818
// OPTIONAL: this forces users to be logged in to use the chatbot.
1919
// 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+
}
2226

2327
return res
2428
}
@@ -27,11 +31,12 @@ export const config = {
2731
matcher: [
2832
/*
2933
* Match all request paths except for the ones starting with:
34+
* - share (publicly shared chats)
3035
* - api (API routes)
3136
* - _next/static (static files)
3237
* - _next/image (image optimization files)
3338
* - favicon.ico (favicon file)
3439
*/
35-
'/((?!api|_next/static|_next/image|favicon.ico).*)'
40+
'/((?!share|api|_next/static|_next/image|favicon.ico).*)'
3641
]
3742
}

0 commit comments

Comments
 (0)