1da90c2756
### What? [1] Clean up `with-supabase` example following patterns from @leerob's recent video on authentication [2] Add images to matcher to reduce number of times a session is refreshed [3] Move instantiation of `cookieStore` into Supabase server helper ### Why? [1] Make template easier to understand and use [2] Reduce likelihood users will receive Auth Rate Limit Exceeded error [3] Makes creating a Supabase client much simpler in Server Components, Route Handlers and Server Actions ### How? [1] Refactor middleware and its helper function [2] Add image extensions to middleware matcher [3] Call `cookies()` function from `createClient` helper - this should still be in the [same execution context](https://nextjs.org/docs/messages/dynamic-server-error) and appears to work from my testing, but would be good to get the 👍 from someone at Vercel
20 lines
636 B
TypeScript
20 lines
636 B
TypeScript
import { type NextRequest } from "next/server";
|
|
import { updateSession } from "@/utils/supabase/middleware";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
return await updateSession(request);
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
/*
|
|
* Match all request paths except:
|
|
* - _next/static (static files)
|
|
* - _next/image (image optimization files)
|
|
* - favicon.ico (favicon file)
|
|
* - images - .svg, .png, .jpg, .jpeg, .gif, .webp
|
|
* Feel free to modify this pattern to include more paths.
|
|
*/
|
|
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
|
|
],
|
|
};
|