g1t/apps/web/app/routes/verify.tsx
| 1 | import { CircleCheck, MailWarning } from "lucide-react"; |
| 2 | import { redirect } from "react-router"; |
| 3 | |
| 4 | import type { Route } from "./+types/verify"; |
| 5 | import { ButtonLink } from "../components/ui"; |
| 6 | import { identity } from "../lib/services.server"; |
| 7 | import { assertSameOrigin, requireUser } from "../lib/session.server"; |
| 8 | |
| 9 | export function meta({}: Route.MetaArgs) { |
| 10 | return [{ title: "Confirm your email · g1t" }]; |
| 11 | } |
| 12 | |
| 13 | /** Follows the link from the confirmation email. */ |
| 14 | export async function loader({ request }: Route.LoaderArgs) { |
| 15 | const token = new URL(request.url).searchParams.get("token") ?? ""; |
| 16 | const result = await identity.verifyEmail(token); |
| 17 | return result.ok |
| 18 | ? { ok: true as const, username: result.value.username } |
| 19 | : { ok: false as const, message: result.error.message }; |
| 20 | } |
| 21 | |
| 22 | /** "Resend" from the banner shown to unconfirmed accounts. */ |
| 23 | export async function action({ request, context }: Route.ActionArgs) { |
| 24 | assertSameOrigin(request); |
| 25 | await identity.resendVerification(requireUser(context, request)); |
| 26 | throw redirect("/?sent=1"); |
| 27 | } |
| 28 | |
| 29 | export default function Verify({ loaderData }: Route.ComponentProps) { |
| 30 | return ( |
| 31 | <main className="mx-auto max-w-md px-4 py-32 text-center"> |
| 32 | {loaderData.ok ? ( |
| 33 | <> |
| 34 | <CircleCheck size={40} className="mx-auto text-accent" /> |
| 35 | <h1 className="mt-6 text-2xl font-semibold tracking-tight"> |
| 36 | Email confirmed |
| 37 | </h1> |
| 38 | <p className="mt-2 text-muted"> |
| 39 | Your account {loaderData.username} is ready. Next, create the |
| 40 | workspace your repositories will live in. |
| 41 | </p> |
| 42 | <div className="mt-8"> |
| 43 | <ButtonLink to="/">Continue</ButtonLink> |
| 44 | </div> |
| 45 | </> |
| 46 | ) : ( |
| 47 | <> |
| 48 | <MailWarning size={40} className="mx-auto text-warn" /> |
| 49 | <h1 className="mt-6 text-2xl font-semibold tracking-tight"> |
| 50 | That link did not work |
| 51 | </h1> |
| 52 | <p className="mt-2 text-muted">{loaderData.message}</p> |
| 53 | <p className="mt-2 text-sm text-muted"> |
| 54 | Sign in and use the banner at the top to send a new one. |
| 55 | </p> |
| 56 | <div className="mt-8"> |
| 57 | <ButtonLink to="/login" variant="quiet"> |
| 58 | Sign in |
| 59 | </ButtonLink> |
| 60 | </div> |
| 61 | </> |
| 62 | )} |
| 63 | </main> |
| 64 | ); |
| 65 | } |