-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
28 lines (22 loc) · 842 Bytes
/
middleware.ts
File metadata and controls
28 lines (22 loc) · 842 Bytes
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
import {NextRequest , NextResponse} from "next/server";
import {auth} from "@/lib/auth"
import {headers} from "next/headers"
import aj from "@/lib/arcjet";
import {detectBot, shield} from "arcjet";
import {createMiddleware} from "@arcjet/next";
export async function middleware(request: NextRequest, response: NextResponse) {
const session=await auth.api.getSession({
headers:await headers()
});
if(!session){
return NextResponse.redirect(new URL('/Sign-In',request.url));
}
return NextResponse.next();
}
const validate=aj
.withRule(shield({mode:'LIVE'}))
.withRule(detectBot({mode:'LIVE',allow:['CATEGORY:SEARCH_ENGINE','G00G1E_CRAWLER']}))
export default createMiddleware(validate);
export const config = {
matcher:["/((?!api|_next/static|_next/image|favicon.ico|Sign-In|assets).*)"]
}