-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
43 lines (37 loc) · 1.2 KB
/
middleware.ts
File metadata and controls
43 lines (37 loc) · 1.2 KB
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
import { NextRequest, NextResponse } from "next/server";
export function middleware(request: NextRequest) {
// Handle CORS for callback routes
if (
request.nextUrl.pathname.startsWith("/callback") ||
request.nextUrl.pathname.startsWith("/api/callback")
) {
// Handle preflight requests
if (request.method === "OPTIONS") {
return new NextResponse(null, {
status: 200,
headers: {
"Access-Control-Allow-Origin": "https://auth.f3nation.com",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Max-Age": "86400",
},
});
}
// Add CORS headers to all callback responses
const response = NextResponse.next();
response.headers.set(
"Access-Control-Allow-Origin",
"https://auth.f3nation.com",
);
response.headers.set("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
response.headers.set(
"Access-Control-Allow-Headers",
"Content-Type, Authorization",
);
return response;
}
return NextResponse.next();
}
export const config = {
matcher: ["/callback/:path*", "/api/callback/:path*"],
};