-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
44 lines (38 loc) · 1.49 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 { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
// This function can be marked `async` if using `await` inside
// export function middleware(request: NextRequest) {
// // return NextResponse.redirect(new URL('/home', request.url))
// // console.log(request)
// const nextUrl = request.nextUrl
// const method = nextUrl.searchParams.get("_method")
// const requestHeaders = new Headers(request.headers)
// requestHeaders.set('x-new-method', method ? method : "NOCHANGE")
// // const response = method ? NextResponse.next({ headers: { method: method }}) : NextResponse.next()
// const response = NextResponse.next({
// request: {
// // New request headers
// headers: requestHeaders,
// },
// })
// // console.log(response)
// // request.method = method ? method : request.method
// return response
// }
const isProtectedRoute = createRouteMatcher([
'/admin(.*)',
]);
export default clerkMiddleware(async (auth, req) => {
if (isProtectedRoute(req)) await auth().protect();
});
// See "Matching Paths" below to learn more
export const config = {
matcher: [
// '/api/session',
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}