-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): setting domain to allow cookies to be shared across subdo…
…mains ??
- Loading branch information
Showing
3 changed files
with
12 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,15 @@ | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
import { validateRequest } from "./server/auth"; | ||
|
||
export function middleware(request: NextRequest) { | ||
const res = NextResponse.next(); | ||
|
||
const origin = request.headers.get("origin"); | ||
const allowedOrigins = ["https://www.readiumx.com", "https://readiumx.com"]; | ||
|
||
if (request.method === "OPTIONS") { | ||
res.headers.append("Access-Control-Allow-Origin", origin!); | ||
res.headers.append("Access-Control-Allow-Credentials", "true"); | ||
res.headers.append( | ||
"Access-Control-Allow-Methods", | ||
"GET,DELETE,PATCH,POST,PUT,OPTIONS", | ||
); | ||
res.headers.append( | ||
"Access-Control-Allow-Headers", | ||
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version", | ||
); | ||
|
||
return res; | ||
export async function middleware(request: NextRequest) { | ||
const { session } = await validateRequest(); | ||
if (!session) { | ||
return NextResponse.redirect(new URL("/signin", request.url)); | ||
} | ||
|
||
if (origin && !allowedOrigins.includes(origin)) { | ||
res.headers.append("Access-Control-Allow-Origin", origin); | ||
} | ||
|
||
res.headers.append("Access-Control-Allow-Credentials", "true"); | ||
res.headers.append( | ||
"Access-Control-Allow-Methods", | ||
"GET,DELETE,PATCH,POST,PUT,OPTIONS", | ||
); | ||
res.headers.append( | ||
"Access-Control-Allow-Headers", | ||
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version", | ||
); | ||
|
||
return res; | ||
return NextResponse.next(); | ||
} | ||
|
||
export const config = { | ||
matcher: "/api/:path*", | ||
matcher: ["/history", "/bookmarks"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters