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