Update route.ts
This commit is contained in:
parent
7938170360
commit
97c63b6d02
@ -1,5 +1,34 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
//import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
//import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
|
||||||
|
//export async function GET(req: NextRequest) {
|
||||||
|
// const { searchParams } = req.nextUrl;
|
||||||
|
// const token = searchParams.get("jwtToken");
|
||||||
|
// const productId = searchParams.get("productId");
|
||||||
|
// const placementId = searchParams.get("placementId");
|
||||||
|
// const paywallId = searchParams.get("paywallId");
|
||||||
|
|
||||||
|
// const redirectUrl = new URL(`${ROUTES.payment()}`, process.env.NEXT_PUBLIC_APP_URL || "");
|
||||||
|
// if (productId) redirectUrl.searchParams.set("productId", productId);
|
||||||
|
// if (placementId) redirectUrl.searchParams.set("placementId", placementId);
|
||||||
|
// if (paywallId) redirectUrl.searchParams.set("paywallId", paywallId);
|
||||||
|
|
||||||
|
// const res = NextResponse.redirect(redirectUrl);
|
||||||
|
|
||||||
|
// res.cookies.set({
|
||||||
|
// name: "accessToken",
|
||||||
|
// value: token || "",
|
||||||
|
// httpOnly: true,
|
||||||
|
// secure: true,
|
||||||
|
// sameSite: "lax",
|
||||||
|
// path: "/",
|
||||||
|
// maxAge: 60 * 60 * 24 * 365,
|
||||||
|
// });
|
||||||
|
// return res;
|
||||||
|
//}
|
||||||
|
|
||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { ROUTES } from "@/shared/constants/client-routes";
|
import { ROUTES } from "@/shared/constants/client-routes";
|
||||||
|
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
@ -14,16 +43,32 @@ export async function GET(req: NextRequest) {
|
|||||||
if (placementId) redirectUrl.searchParams.set("placementId", placementId);
|
if (placementId) redirectUrl.searchParams.set("placementId", placementId);
|
||||||
if (paywallId) redirectUrl.searchParams.set("paywallId", paywallId);
|
if (paywallId) redirectUrl.searchParams.set("paywallId", paywallId);
|
||||||
|
|
||||||
const res = NextResponse.redirect(redirectUrl);
|
// Ставим куку через заголовок Set-Cookie, тк в HTML-ответе NextResponse.cookies не работает
|
||||||
|
const cookie = [
|
||||||
|
`accessToken=${encodeURIComponent(token || "")}`,
|
||||||
|
`HttpOnly; Secure; Path=/; SameSite=Lax; Max-Age=${60 * 60 * 24 * 365}`,
|
||||||
|
].join("; ");
|
||||||
|
|
||||||
res.cookies.set({
|
const html = `
|
||||||
name: "accessToken",
|
<!DOCTYPE html>
|
||||||
value: token || "",
|
<html>
|
||||||
httpOnly: true,
|
<head>
|
||||||
secure: true,
|
<meta http-equiv="refresh" content="0; url=${redirectUrl}" />
|
||||||
sameSite: "lax",
|
<script>
|
||||||
path: "/",
|
window.location.replace(${JSON.stringify(redirectUrl.toString())});
|
||||||
maxAge: 60 * 60 * 24 * 365,
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Redirecting...</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
|
||||||
|
return new NextResponse(html, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"content-type": "text/html; charset=utf-8",
|
||||||
|
"set-cookie": cookie,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return res;
|
}
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user