File tree 1 file changed +21
-1
lines changed 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,27 @@ export async function middleware(req: NextRequest) {
11
11
12
12
// Refresh session if expired - required for Server Components
13
13
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs#managing-session-with-middleware
14
- await supabase . auth . getSession ( )
14
+ const {
15
+ data : { session }
16
+ } = await supabase . auth . getSession ( )
17
+
18
+ // OPTIONAL: this forces users to be logged in to use the chatbot.
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 ) )
15
22
16
23
return res
17
24
}
25
+
26
+ export const config = {
27
+ matcher : [
28
+ /*
29
+ * Match all request paths except for the ones starting with:
30
+ * - api (API routes)
31
+ * - _next/static (static files)
32
+ * - _next/image (image optimization files)
33
+ * - favicon.ico (favicon file)
34
+ */
35
+ '/((?!api|_next/static|_next/image|favicon.ico).*)'
36
+ ]
37
+ }
You can’t perform that action at this time.
0 commit comments