22 lines
645 B
TypeScript
22 lines
645 B
TypeScript
import { createMiddlewareClient } from '@supabase/auth-helpers-nextjs';
|
|
import { NextResponse } from 'next/server';
|
|
import type { NextRequest } from 'next/server';
|
|
|
|
export async function middleware(req: NextRequest) {
|
|
const res = NextResponse.next();
|
|
|
|
// Create a Supabase client configured to use cookies
|
|
const supabase = createMiddlewareClient({ req, res });
|
|
|
|
// Refresh session if expired - required for Server Components
|
|
await supabase.auth.getSession();
|
|
|
|
return res;
|
|
}
|
|
|
|
// Specify the paths where this middleware should run
|
|
export const config = {
|
|
matcher: [
|
|
'/((?!_next/static|_next/image|favicon.ico).*)',
|
|
],
|
|
};
|