feat: signup toggle, invite links, admin-created users

- New invites table: token-gated signup, optional email lock,
  role/tier override, single-use, expiry.
- SIGNUPS_DISABLED site setting toggle at /admin/settings.
- databaseHooks.user.create gate in auth/server.ts blocks new account
  creation (email + Google OAuth) when disabled unless a valid invite
  cookie is present; applies invite role/tier and marks it consumed.
- /admin/invites: create/list/revoke shareable invite links.
- /admin/users: "Create user" dialog — admin sets email/role/tier,
  account is pre-verified, user gets a set-password email (admin
  never sees a password).
- Signup page reads ?invite=, validates via public
  /api/v1/invites/[token], locks the form when signups are closed
  and no valid invite is present.
- proxy.ts: allowlist /api/v1/invites/ for anonymous invite checks.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-03 21:36:40 +02:00
parent c5bc2e1470
commit e0e1ac49d9
22 changed files with 4483 additions and 90 deletions
+10 -83
View File
@@ -1,86 +1,13 @@
"use client";
import { isSignupsDisabled } from "@/lib/site-settings";
import { SignupForm } from "./signup-form";
import { useState } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { toast } from "sonner";
import { useTranslations } from "next-intl";
import { authClient } from "@/lib/auth/client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
export default async function SignupPage({
searchParams,
}: {
searchParams: Promise<{ invite?: string }>;
}) {
const { invite } = await searchParams;
const signupsDisabled = await isSignupsDisabled();
export default function SignupPage() {
const router = useRouter();
const t = useTranslations("auth");
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setLoading(true);
const { error } = await authClient.signUp.email({
name,
email,
password,
callbackURL: "/recipes",
});
setLoading(false);
if (error) {
toast.error(error.message ?? "Sign up failed");
} else {
toast.success("Account created — check your email to verify");
router.push("/login");
}
}
async function handleGoogle() {
await authClient.signIn.social({ provider: "google", callbackURL: "/recipes" });
}
return (
<Card>
<CardHeader className="space-y-1">
<CardTitle className="text-2xl font-semibold tracking-tight">{t("signUpTitle")}</CardTitle>
<CardDescription>{t("signUpSubtitle")}</CardDescription>
</CardHeader>
<form onSubmit={handleSubmit}>
<CardContent className="space-y-4">
<Button variant="outline" className="w-full" type="button" onClick={handleGoogle}>
{t("continueWithGoogle")}
</Button>
<div className="flex items-center gap-2">
<Separator className="flex-1" />
<span className="text-xs text-muted-foreground">{t("or")}</span>
<Separator className="flex-1" />
</div>
<div className="space-y-2">
<Label htmlFor="name">{t("name")}</Label>
<Input id="name" type="text" placeholder={t("namePlaceholder")} value={name} onChange={(e) => setName(e.target.value)} required />
</div>
<div className="space-y-2">
<Label htmlFor="email">{t("email")}</Label>
<Input id="email" type="email" placeholder={t("emailPlaceholder")} value={email} onChange={(e) => setEmail(e.target.value)} required />
</div>
<div className="space-y-2">
<Label htmlFor="password">{t("password")}</Label>
<Input id="password" type="password" value={password} onChange={(e) => setPassword(e.target.value)} required minLength={8} />
</div>
<Button className="w-full" type="submit" disabled={loading}>
{loading ? t("signUpLoading") : t("signUpTitle")}
</Button>
</CardContent>
</form>
<CardFooter className="flex justify-center">
<p className="text-sm text-muted-foreground">
{t("alreadyHaveAccount")}{" "}
<Link href="/login" className="underline underline-offset-4 hover:text-foreground">{t("signIn")}</Link>
</p>
</CardFooter>
</Card>
);
return <SignupForm signupsDisabled={signupsDisabled} inviteToken={invite ?? null} />;
}