mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 09:20:24 -05:00
25 lines
844 B
TypeScript
25 lines
844 B
TypeScript
import type { ActionFunction } from "@remix-run/node";
|
|
import { redirect } from "@remix-run/node";
|
|
import { IMPERSONATED_SESSION_KEY } from "~/core/auth/authenticator.server";
|
|
import { sessionStorage } from "~/core/auth/session.server";
|
|
|
|
export const action: ActionFunction = async ({ request }) => {
|
|
if (!["development", "test"].includes(process.env.NODE_ENV)) return null;
|
|
|
|
const session = await sessionStorage.getSession(
|
|
request.headers.get("Cookie")
|
|
);
|
|
|
|
const url = new URL(request.url);
|
|
const rawId = url.searchParams.get("id");
|
|
|
|
const userId = Number(url.searchParams.get("id"));
|
|
if (!rawId || Number.isNaN(userId)) throw new Response(null, { status: 400 });
|
|
|
|
session.set(IMPERSONATED_SESSION_KEY, userId);
|
|
|
|
throw redirect("/", {
|
|
headers: { "Set-Cookie": await sessionStorage.commitSession(session) },
|
|
});
|
|
};
|