forked from vercel/nextjs-subscription-payments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
37 lines (31 loc) · 1.11 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
import { type NextRequest, NextResponse } from 'next/server'
import { updateSession } from '@/utils/supabase/middleware';
import { basicAuth } from '@/utils/middleware/basic-auth';
import { multiTenant } from '@/utils/middleware/multi-tenant';
export async function middleware(request: NextRequest) {
const handlers = [basicAuth, multiTenant, updateSession]
const response = NextResponse.next()
for (const handler of handlers) {
const handlerResponse = await handler(request, response)
if (handlerResponse === response) {
// Continue to the next handler
continue
} else if (handlerResponse instanceof NextResponse) {
return handlerResponse
}
}
return response
}
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.
*/
'/((?!api|_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'
]
};