30 lines
859 B
TypeScript
30 lines
859 B
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
|
||
|
|
export async function POST(request: NextRequest) {
|
||
|
|
const allCookies = request.cookies.getAll();
|
||
|
|
const zammadURL = process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080";
|
||
|
|
const signOutURL = `${zammadURL}/api/v1/signout`;
|
||
|
|
const headers = {
|
||
|
|
"Content-Type": "application/json",
|
||
|
|
Accept: "application/json",
|
||
|
|
Cookie: allCookies
|
||
|
|
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||
|
|
.join("; "),
|
||
|
|
};
|
||
|
|
|
||
|
|
await fetch(signOutURL, { headers });
|
||
|
|
|
||
|
|
const cookiePrefixesToRemove = ["_zammad"];
|
||
|
|
const response = NextResponse.json({ message: "ok" });
|
||
|
|
|
||
|
|
for (const cookie of allCookies) {
|
||
|
|
if (
|
||
|
|
cookiePrefixesToRemove.some((prefix) => cookie.name.startsWith(prefix))
|
||
|
|
) {
|
||
|
|
response.cookies.set(cookie.name, "", { path: "/", maxAge: 0 });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return response;
|
||
|
|
}
|