13 lines · 562 BRaw
| 1 | import { data, redirect } from "react-router"; |
| 2 | import type { Route } from "./+types/switch"; |
| 3 | import { formText, namespaceCookie, signedIn } from "../lib/session"; |
| 4 | |
| 5 | export async function action({ request, context }: Route.ActionArgs) { |
| 6 | const slug = formText(await request.formData(), "namespace"); |
| 7 | if (!signedIn(context).viewer.namespaces.some((namespace) => namespace.slug === slug)) throw data(null, { status: 404 }); |
| 8 | throw redirect(`/${slug}`, { headers: { "Set-Cookie": namespaceCookie(slug) } }); |
| 9 | } |
| 10 | |
| 11 | export function loader() { |
| 12 | throw redirect("/"); |
| 13 | } |