Login, logout and middleware updates
This commit is contained in:
parent
f552f8024f
commit
9fb3665ced
18 changed files with 96 additions and 50 deletions
29
apps/link/app/api/logout/route.ts
Normal file
29
apps/link/app/api/logout/route.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue