30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { ActionFunction, redirect } from "react-router";
|
|
import { getDomainRoutingConfig } from "@hivegrid/config";
|
|
import { withMetrics } from "~/lib/metrics/ssr";
|
|
import { createLogLogout } from "~/utils/db/logs.db.server";
|
|
import { absoluteAppRootPath } from "~/utils/app/CrossHostUrls";
|
|
import { getHostRoutingContextFromRequest } from "~/utils/app/HostRouting.server";
|
|
|
|
import { getUserInfo, logout, validateCSRFToken } from "~/utils/session.server";
|
|
|
|
export const action: ActionFunction = async ({ request }) => {
|
|
await validateCSRFToken(request);
|
|
if (getHostRoutingContextFromRequest(request) === "admin") {
|
|
// Preserve the POST body across the same-host redirect so the dedicated
|
|
// route can validate CSRF again and perform Authentik RP-initiated logout.
|
|
return redirect("/auth/admin/logout", {
|
|
status: 307,
|
|
headers: { "Cache-Control": "no-store" },
|
|
});
|
|
}
|
|
const userInfo = await getUserInfo(request);
|
|
if (userInfo.userId) {
|
|
createLogLogout(request, userInfo.userId);
|
|
}
|
|
return logout(request);
|
|
};
|
|
|
|
export const loader = withMetrics("logout", async () => {
|
|
throw redirect(absoluteAppRootPath(getDomainRoutingConfig()));
|
|
});
|