parent
3fb493f400
commit
1ce55e4091
2016 changed files with 23595 additions and 15662 deletions
61
middleware.ts
Normal file
61
middleware.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { createServerClient } from '@supabase/ssr'
|
||||
import type { CookieOptions } from '@supabase/ssr'
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
const response = NextResponse.next()
|
||||
|
||||
const supabase = createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{
|
||||
cookies: {
|
||||
get(name: string) {
|
||||
return request.cookies.get(name)?.value
|
||||
},
|
||||
set(name: string, value: string, options: CookieOptions) {
|
||||
response.cookies.set({
|
||||
name,
|
||||
value,
|
||||
path: options?.path ?? '/',
|
||||
maxAge: options?.maxAge ?? 0,
|
||||
domain: options?.domain,
|
||||
secure: options?.secure,
|
||||
httpOnly: options?.httpOnly,
|
||||
sameSite: options?.sameSite,
|
||||
})
|
||||
},
|
||||
remove(name: string, options: CookieOptions) {
|
||||
response.cookies.set({
|
||||
name,
|
||||
value: '',
|
||||
path: options?.path ?? '/',
|
||||
maxAge: 0,
|
||||
domain: options?.domain,
|
||||
secure: options?.secure,
|
||||
httpOnly: options?.httpOnly,
|
||||
sameSite: options?.sameSite,
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
await supabase.auth.getUser()
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Match all request paths except for the ones starting with:
|
||||
* - _next/static (static files)
|
||||
* - _next/image (image optimization files)
|
||||
* - favicon.ico (favicon file)
|
||||
* Feel free to modify this pattern to include more paths.
|
||||
*/
|
||||
'/((?!_next/static|_next/image|favicon.ico).*)',
|
||||
],
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue