forked from ivanjameslo/kopi82
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
44 lines (32 loc) · 1.5 KB
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { supabase } from './lib/initSupabase';
import { updateSession } from './lib/supabaseServer';
export async function middleware(request: NextRequest) {
return await updateSession(request);
}
// Specify the paths that the middleware should run on
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
// import { NextResponse } from 'next/server';
// import type { NextRequest } from 'next/server';
// import { updateSession } from './lib/supabaseServer';
// export async function middleware(request: NextRequest) {
// // Call updateSession to get user data and cookies
// const { sessionData, supabaseResponse, publicPaths } = await updateSession(request);
// // Redirect authenticated users away from /login to the home page
// if (sessionData && request.nextUrl.pathname === '/Login') {
// return NextResponse.redirect(new URL('/', request.url));
// }
// // If there's no session and the user is trying to access a protected page, redirect to /login
// if (!sessionData && !publicPaths.includes(request.nextUrl.pathname.toLowerCase())) {
// return NextResponse.redirect(new URL('/Login', request.url));
// }
// // Proceed if session exists or if it's a public route
// return supabaseResponse;
// }
// // Specify the paths that the middleware should run on
// export const config = {
// matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
// };