-dev.ts
This file
Path
apps/web/src/routes/auth/-dev.ts
26 lines · 957 bytes · TypeScript
Last changed by
Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
History of this fileTake it
123456789101112131415161718192021222324252627// Development only: the leading `-` keeps this module out of the route tree, and only a development build imports it.import { Handle } from "@repo/protocol/ids";import { Option, Schema } from "effect";
import type { Handled } from "../../server/session.ts";import { redirect, returnPath, sessionCookie } from "../../server/session.ts";
const DEV_SESSION_SECONDS = 8 * 60 * 60;
const decodeHandle = Schema.decodeUnknownOption(Handle);
export const devSignIn = ({ request }: Handled): Response => { const here = new URL(request.url);
return Option.match(decodeHandle(here.searchParams.get("handle")), { onNone: () => new Response("Give a handle: /auth/dev?handle=<handle>", { headers: { "cache-control": "no-store" }, status: 400, }), onSome: (handle) => redirect(returnPath(here.origin, here.searchParams.get("return")), [ sessionCookie(`dev-${handle}`, DEV_SESSION_SECONDS), ]), });};