Skip to content

Commit

Permalink
fix: allow public access for share route.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwebdev committed Jul 7, 2023
1 parent 2052847 commit 045b0b9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export async function middleware(req: NextRequest) {

// OPTIONAL: this forces users to be logged in to use the chatbot.
// If you want to allow anonymous users, simply remove the check below.
if (!session && !req.url.includes('/sign-in'))
return NextResponse.redirect(new URL('/sign-in', req.url))
if (!session && !req.url.includes('/sign-in')) {
const redirectUrl = req.nextUrl.clone()
redirectUrl.pathname = '/sign-in'
redirectUrl.searchParams.set(`redirectedFrom`, req.nextUrl.pathname)
return NextResponse.redirect(redirectUrl)
}

return res
}
Expand All @@ -27,11 +31,12 @@ export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - share (publicly shared chats)
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)'
'/((?!share|api|_next/static|_next/image|favicon.ico).*)'
]
}

0 comments on commit 045b0b9

Please sign in to comment.