@lalternative/auth 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-session.ts","../src/components/login-form.tsx","../src/components/social-buttons.tsx","../src/components/register-form.tsx","../src/components/verify-email-form.tsx","../src/components/forgot-password-form.tsx","../src/components/reset-password-form.tsx","../src/components/auth-layout.tsx","../src/components/invitation-notice.tsx"],"sourcesContent":["import type { PlatformAuthClient } from \"../client\"\n\n/**\n * Returns a useSession hook bound to the given auth client.\n * Usage: const { data: session, isPending } = useSession(authClient)\n */\nexport function useSession(authClient: PlatformAuthClient) {\n return authClient.useSession()\n}\n\n/**\n * Returns a logout function bound to the given auth client.\n * Usage: const logout = useLogout(authClient)\n */\nexport function useLogout(authClient: PlatformAuthClient) {\n const signOut = async () => {\n await authClient.signOut()\n }\n return signOut\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { LoginFormProps } from \"../types\"\nimport { SocialButtons } from \"./social-buttons\"\n\n// accountLinking is disabled in createPlatformAuth, so a social sign-in on an\n// address already registered with a password is refused with this code. Without\n// a message the button reads as broken rather than as a rejected account.\nfunction oauthErrorMessage(code: string): string {\n switch (code) {\n case \"account_not_linked\":\n return \"This email is already registered with a password. Sign in with your password instead.\"\n case \"access_denied\":\n return \"Sign-in was cancelled.\"\n default:\n return \"Sign-in failed. Please try again.\"\n }\n}\n\nexport function LoginForm({\n onSuccess,\n registerUrl = \"/register\",\n forgotPasswordUrl = \"/forgot-password\",\n socialCallbackUrl = \"/\",\n socialProviders = [],\n coreTokenUrl = \"/api/auth/core-token\",\n authClient,\n}: LoginFormProps) {\n const [email, setEmail] = useState(\"\")\n const [password, setPassword] = useState(\"\")\n const [error, setError] = useState<string | undefined>()\n const [isPending, setIsPending] = useState(false)\n\n const handleSubmit = async (e: FormEvent) => {\n e.preventDefault()\n if (!email.trim()) {\n setError(\"Please enter your email address\")\n return\n }\n if (!password) {\n setError(\"Please enter your password\")\n return\n }\n setError(undefined)\n setIsPending(true)\n try {\n const res = await authClient.signIn.email({\n email: email.trim(),\n password,\n })\n if (res?.error) {\n setError(res.error.message ?? \"Invalid email or password\")\n return\n }\n // The better-auth session cookie alone does not authenticate the Go core:\n // it verifies the EdDSA JWT minted here against the issuer's JWKS. Skipped\n // when the app has no core to call.\n if (coreTokenUrl) {\n await fetch(coreTokenUrl, { credentials: \"include\" })\n }\n onSuccess?.()\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Invalid email or password\")\n } finally {\n setIsPending(false)\n }\n }\n\n const handleSocial = async (provider: \"google\" | \"github\") => {\n setError(undefined)\n try {\n await authClient.signIn.social({\n provider,\n callbackURL: socialCallbackUrl,\n })\n } catch (err) {\n setError(\n err instanceof Error ? oauthErrorMessage(err.message) : oauthErrorMessage(\"\"),\n )\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">Sign in</h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n Welcome back. Enter your credentials to continue.\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n <form onSubmit={handleSubmit} className=\"space-y-4\" noValidate>\n <input\n type=\"email\"\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n placeholder=\"Email address\"\n required\n disabled={isPending}\n autoComplete=\"email\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <div className=\"space-y-1\">\n <input\n type=\"password\"\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n placeholder=\"Password\"\n required\n disabled={isPending}\n autoComplete=\"current-password\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n <div className=\"text-right\">\n <a\n href={forgotPasswordUrl}\n className=\"text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground\"\n >\n Forgot your password?\n </a>\n </div>\n </div>\n\n <button\n type=\"submit\"\n disabled={isPending || !email.trim() || !password}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isPending ? \"Signing in...\" : \"Sign in\"}\n </button>\n </form>\n\n <SocialButtons\n providers={socialProviders}\n onSelect={handleSocial}\n disabled={isPending}\n />\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Don&apos;t have an account?{\" \"}\n <a\n href={registerUrl}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign up\n </a>\n </p>\n </div>\n )\n}\n","const LABELS: Record<string, string> = {\n google: \"Continue with Google\",\n github: \"Continue with GitHub\",\n}\n\ninterface SocialButtonsProps {\n providers: Array<\"google\" | \"github\">\n onSelect: (provider: \"google\" | \"github\") => void | Promise<void>\n disabled?: boolean\n}\n\nexport function SocialButtons({\n providers,\n onSelect,\n disabled = false,\n}: SocialButtonsProps) {\n if (providers.length === 0) return null\n\n return (\n <div className=\"space-y-4\">\n <div className=\"relative\">\n <div className=\"absolute inset-0 flex items-center\">\n <div className=\"w-full border-t border-input\" />\n </div>\n <div className=\"relative flex justify-center\">\n <span className=\"bg-background px-2 text-xs uppercase tracking-wider text-muted-foreground\">\n or\n </span>\n </div>\n </div>\n\n <div className=\"space-y-2\">\n {providers.map((provider) => (\n <button\n key={provider}\n type=\"button\"\n onClick={() => onSelect(provider)}\n disabled={disabled}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50\"\n >\n {LABELS[provider] ?? provider}\n </button>\n ))}\n </div>\n </div>\n )\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { RegisterFormProps } from \"../types\"\nimport { SocialButtons } from \"./social-buttons\"\n\nconst MIN_PASSWORD_LENGTH = 8\n\nexport function RegisterForm({\n onSuccess,\n loginUrl = \"/login\",\n legal,\n socialCallbackUrl = \"/\",\n socialProviders = [],\n authClient,\n}: RegisterFormProps) {\n const [name, setName] = useState(\"\")\n const [email, setEmail] = useState(\"\")\n const [password, setPassword] = useState(\"\")\n const [error, setError] = useState<string | undefined>()\n const [isPending, setIsPending] = useState(false)\n\n const handleSubmit = async (e: FormEvent) => {\n e.preventDefault()\n if (!name.trim()) {\n setError(\"Please enter your name\")\n return\n }\n if (!email.trim()) {\n setError(\"Please enter your email address\")\n return\n }\n if (password.length < MIN_PASSWORD_LENGTH) {\n setError(`Password must be at least ${MIN_PASSWORD_LENGTH} characters`)\n return\n }\n setError(undefined)\n setIsPending(true)\n try {\n const res = await authClient.signUp.email({\n name: name.trim(),\n email: email.trim(),\n password,\n })\n if (res?.error) {\n setError(res.error.message ?? \"Could not create your account\")\n return\n }\n // createPlatformAuth sets requireEmailVerification, so sign-up leaves the\n // account unverified and without a session: the caller routes to the OTP\n // step rather than into the app.\n onSuccess?.(email.trim())\n } catch (err) {\n setError(\n err instanceof Error ? err.message : \"Could not create your account\",\n )\n } finally {\n setIsPending(false)\n }\n }\n\n const handleSocial = async (provider: \"google\" | \"github\") => {\n setError(undefined)\n try {\n await authClient.signIn.social({\n provider,\n callbackURL: socialCallbackUrl,\n })\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Sign-up failed\")\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">Create an account</h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n We&apos;ll send you a code to confirm your email address.\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n <form onSubmit={handleSubmit} className=\"space-y-4\" noValidate>\n <input\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder=\"Full name\"\n required\n disabled={isPending}\n autoComplete=\"name\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <input\n type=\"email\"\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n placeholder=\"Email address\"\n required\n disabled={isPending}\n autoComplete=\"email\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <div className=\"space-y-1\">\n <input\n type=\"password\"\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n placeholder=\"Password\"\n required\n disabled={isPending}\n autoComplete=\"new-password\"\n aria-describedby=\"register-password-hint\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n <p id=\"register-password-hint\" className=\"text-xs text-muted-foreground\">\n At least {MIN_PASSWORD_LENGTH} characters.\n </p>\n </div>\n\n <button\n type=\"submit\"\n disabled={isPending}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isPending ? \"Creating account...\" : \"Create account\"}\n </button>\n\n {legal && (\n <div className=\"text-center text-xs text-muted-foreground\">{legal}</div>\n )}\n </form>\n\n <SocialButtons\n providers={socialProviders}\n onSelect={handleSocial}\n disabled={isPending}\n />\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Already have an account?{\" \"}\n <a\n href={loginUrl}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { VerifyEmailFormProps } from \"../types\"\n\nexport function VerifyEmailForm({\n email,\n onSuccess,\n authClient,\n}: VerifyEmailFormProps) {\n const [otp, setOtp] = useState(\"\")\n const [isVerifying, setIsVerifying] = useState(false)\n const [isResending, setIsResending] = useState(false)\n const [resendMessage, setResendMessage] = useState<string | undefined>()\n const [error, setError] = useState<string | undefined>()\n\n const handleVerify = async (e: FormEvent) => {\n e.preventDefault()\n if (!otp.trim() || otp.length < 6) {\n setError(\"Please enter the 6-digit code\")\n return\n }\n setError(undefined)\n setIsVerifying(true)\n try {\n const res = await authClient.emailOtp.verifyEmail({ email, otp })\n console.log(\"[verify-email] response:\", JSON.stringify(res?.data), \"error:\", JSON.stringify(res?.error))\n if (res?.error) {\n setError(res.error.message ?? \"Invalid code. Please try again.\")\n return\n }\n onSuccess?.()\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Invalid code. Please try again.\")\n } finally {\n setIsVerifying(false)\n }\n }\n\n const handleResend = async () => {\n if (!email) {\n setError(\"Email address is not available. Please register again.\")\n return\n }\n setError(undefined)\n setResendMessage(undefined)\n setIsResending(true)\n try {\n await authClient.emailOtp.sendVerificationOtp({\n email,\n type: \"email-verification\",\n })\n setResendMessage(\"A new code has been sent to your inbox.\")\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to resend code.\")\n } finally {\n setIsResending(false)\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">\n Verify your email\n </h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n {email ? (\n <>\n Enter the 6-digit code sent to{\" \"}\n <span className=\"font-medium text-foreground\">{email}</span>\n </>\n ) : (\n \"Enter the 6-digit code sent to your email\"\n )}\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n {resendMessage && (\n <div className=\"rounded-lg border border-green-200 bg-green-50 px-3 py-2 text-xs text-green-700\">\n {resendMessage}\n </div>\n )}\n\n <form onSubmit={handleVerify} className=\"space-y-4\" noValidate>\n <input\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]*\"\n maxLength={6}\n value={otp}\n onChange={(e) => setOtp(e.target.value.replace(/\\D/g, \"\"))}\n placeholder=\"000000\"\n required\n disabled={isVerifying}\n autoComplete=\"one-time-code\"\n className=\"flex h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-lg tracking-[0.4em] font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <button\n type=\"submit\"\n disabled={isVerifying || otp.length < 6}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isVerifying ? \"Verifying...\" : \"Verify email\"}\n </button>\n\n <button\n type=\"button\"\n onClick={handleResend}\n disabled={isResending}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50\"\n >\n {isResending ? \"Sending...\" : \"Resend code\"}\n </button>\n </form>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Already verified?{\" \"}\n <a\n href=\"/login\"\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { ForgotPasswordFormProps } from \"../types\"\n\nexport function ForgotPasswordForm({\n onSuccess,\n loginUrl = \"/login\",\n authClient,\n}: ForgotPasswordFormProps) {\n const [email, setEmail] = useState(\"\")\n const [error, setError] = useState<string | undefined>()\n const [isPending, setIsPending] = useState(false)\n\n const handleSubmit = async (e: FormEvent) => {\n e.preventDefault()\n if (!email.trim()) {\n setError(\"Please enter your email address\")\n return\n }\n setError(undefined)\n setIsPending(true)\n try {\n const res = await authClient.emailOtp.sendVerificationOtp({\n email,\n type: \"forget-password\",\n })\n if (res?.error) {\n setError(res.error.message ?? \"Failed to send reset code\")\n return\n }\n onSuccess?.(email)\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to send reset code\")\n } finally {\n setIsPending(false)\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">\n Forgot your password?\n </h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n Enter your email address and we'll send you a code to reset your\n password.\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n <form onSubmit={handleSubmit} className=\"space-y-4\" noValidate>\n <input\n type=\"email\"\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n placeholder=\"Email address\"\n required\n disabled={isPending}\n autoComplete=\"email\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <button\n type=\"submit\"\n disabled={isPending || !email.trim()}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isPending ? \"Sending...\" : \"Send reset code\"}\n </button>\n </form>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Remember your password?{\" \"}\n <a\n href={loginUrl}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import { useState, type FormEvent } from \"react\"\nimport type { ResetPasswordFormProps } from \"../types\"\n\nexport function ResetPasswordForm({\n email,\n onSuccess,\n loginUrl = \"/login\",\n authClient,\n}: ResetPasswordFormProps) {\n const [otp, setOtp] = useState(\"\")\n const [password, setPassword] = useState(\"\")\n const [confirmPassword, setConfirmPassword] = useState(\"\")\n const [error, setError] = useState<string | undefined>()\n const [isResetting, setIsResetting] = useState(false)\n const [isResending, setIsResending] = useState(false)\n const [resendMessage, setResendMessage] = useState<string | undefined>()\n\n const handleSubmit = async (e: FormEvent) => {\n e.preventDefault()\n if (!otp.trim() || otp.length < 6) {\n setError(\"Please enter the 6-digit code\")\n return\n }\n if (password.length < 8) {\n setError(\"Password must be at least 8 characters\")\n return\n }\n if (password !== confirmPassword) {\n setError(\"Passwords do not match\")\n return\n }\n setError(undefined)\n setIsResetting(true)\n try {\n const res = await fetch(\"/api/auth/email-otp/reset-password\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email, otp, password }),\n })\n if (!res.ok) {\n const body = await res.json().catch(() => null)\n setError(body?.message ?? \"Failed to reset password\")\n return\n }\n onSuccess?.()\n } catch (err) {\n setError(\n err instanceof Error ? err.message : \"Failed to reset password\",\n )\n } finally {\n setIsResetting(false)\n }\n }\n\n const handleResend = async () => {\n setError(undefined)\n setResendMessage(undefined)\n setIsResending(true)\n try {\n await authClient.emailOtp.sendVerificationOtp({\n email,\n type: \"forget-password\",\n })\n setResendMessage(\"A new code has been sent to your inbox.\")\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to resend code.\")\n } finally {\n setIsResending(false)\n }\n }\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">\n Reset your password\n </h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n Enter the 6-digit code sent to{\" \"}\n <span className=\"font-medium text-foreground\">{email}</span> and your\n new password.\n </p>\n </div>\n\n {error && (\n <div className=\"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive\">\n {error}\n </div>\n )}\n\n {resendMessage && (\n <div className=\"rounded-lg border border-green-200 bg-green-50 px-3 py-2 text-xs text-green-700\">\n {resendMessage}\n </div>\n )}\n\n <form onSubmit={handleSubmit} className=\"space-y-4\" noValidate>\n <input\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]*\"\n maxLength={6}\n value={otp}\n onChange={(e) => setOtp(e.target.value.replace(/\\D/g, \"\"))}\n placeholder=\"000000\"\n required\n disabled={isResetting}\n autoComplete=\"one-time-code\"\n className=\"flex h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-lg tracking-[0.4em] font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <input\n type=\"password\"\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n placeholder=\"New password\"\n required\n disabled={isResetting}\n autoComplete=\"new-password\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <input\n type=\"password\"\n value={confirmPassword}\n onChange={(e) => setConfirmPassword(e.target.value)}\n placeholder=\"Confirm new password\"\n required\n disabled={isResetting}\n autoComplete=\"new-password\"\n className=\"flex h-11 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed\"\n />\n\n <button\n type=\"submit\"\n disabled={isResetting || otp.length < 6 || !password}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50\"\n >\n {isResetting ? \"Resetting...\" : \"Reset password\"}\n </button>\n\n <button\n type=\"button\"\n onClick={handleResend}\n disabled={isResending}\n className=\"inline-flex h-11 w-full items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50\"\n >\n {isResending ? \"Sending...\" : \"Resend code\"}\n </button>\n </form>\n\n <p className=\"text-center text-sm text-muted-foreground\">\n Remember your password?{\" \"}\n <a\n href={loginUrl}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n Sign in\n </a>\n </p>\n </div>\n )\n}\n","import type { AuthLayoutProps } from \"../types\"\n\nexport function AuthLayout({\n logo,\n title,\n subtitle,\n children,\n footer,\n}: AuthLayoutProps) {\n return (\n <div className=\"flex min-h-screen items-center justify-center bg-background\">\n <div className=\"w-full max-w-md\">\n <div className=\"mb-10 text-center\">\n {logo && <div className=\"mb-6 flex justify-center\">{logo}</div>}\n <h1 className=\"text-[32px] font-light tracking-tight\">{title}</h1>\n {subtitle && (\n <p className=\"mt-2 text-sm text-muted-foreground\">{subtitle}</p>\n )}\n </div>\n\n <div className=\"rounded-xl border bg-card p-8 shadow-sm\">\n {children}\n </div>\n\n {footer && (\n <div className=\"mt-6 text-center text-xs text-muted-foreground\">\n {footer}\n </div>\n )}\n </div>\n </div>\n )\n}\n","import type { InvitationNoticeProps } from \"../types\"\n\n/**\n * Every app is reachable at contact@ its own apex domain, so the address is\n * derived rather than configured. Sub-domains are stripped because the app is\n * routinely served from app./admin. while the mailbox lives on the apex;\n * multi-part public suffixes (.co.uk) would need a real suffix list and no app\n * using this is on one.\n */\nfunction defaultSupportEmail(): string | undefined {\n if (typeof window === \"undefined\") return undefined\n const host = window.location.hostname\n if (!host || host === \"localhost\" || /^[\\d.]+$/.test(host)) return undefined\n const apex = host.split(\".\").slice(-2).join(\".\")\n return `contact@${apex}`\n}\n\nconst REASON_MESSAGE: Record<string, string> = {\n expired: \"Cette invitation a expiré.\",\n claimed: \"Cette invitation a déjà été utilisée.\",\n unknown: \"Ce lien d'invitation n'est pas valide.\",\n}\n\n/**\n * What an invitee sees when their link does not work.\n *\n * It names the reason instead of merging the cases into one message: \"expired\"\n * tells someone their link was real and that asking for another one is worth\n * it, which \"invalid\" does not. Short TTLs make that distinction routine.\n *\n * The only way forward offered is a mailto, deliberately. A self-service\n * \"request a new invitation\" form would mean a public endpoint accepting dead\n * tokens, a queue to moderate, and a way to probe which tokens once existed —\n * for a flow where the operator already knows the person by name.\n */\nexport function InvitationNotice({\n reason = \"unknown\",\n supportEmail,\n title = \"Invitation indisponible\",\n action,\n}: InvitationNoticeProps) {\n const contact = supportEmail ?? defaultSupportEmail()\n\n return (\n <div className=\"space-y-8\">\n <div>\n <h1 className=\"text-2xl font-bold tracking-tight\">{title}</h1>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n {REASON_MESSAGE[reason] ?? REASON_MESSAGE.unknown}\n </p>\n </div>\n\n {contact ? (\n <p className=\"text-sm text-muted-foreground\">\n Écrivez-nous à{\" \"}\n <a\n href={`mailto:${contact}`}\n className=\"font-medium text-foreground underline underline-offset-4 hover:text-foreground/80\"\n >\n {contact}\n </a>{\" \"}\n pour en recevoir une nouvelle.\n </p>\n ) : null}\n\n {action}\n </div>\n )\n}\n"],"mappings":";;;;;AAMO,SAAS,WAAW,YAAgC;AACzD,SAAO,WAAW,WAAW;AAC/B;AAMO,SAAS,UAAU,YAAgC;AACxD,QAAM,UAAU,YAAY;AAC1B,UAAM,WAAW,QAAQ;AAAA,EAC3B;AACA,SAAO;AACT;;;ACnBA,SAAS,gBAAgC;;;ACoBnC,SAEI,KAFJ;AApBN,IAAM,SAAiC;AAAA,EACrC,QAAQ;AAAA,EACR,QAAQ;AACV;AAQO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAAuB;AACrB,MAAI,UAAU,WA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,SAAS,eAAe,WAAW,KAAK,IAAI,EAAG,QAAO;AACnE,QAAM,OAAO,KAAK,MAAM,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,GAAG;AAC/C,SAAO,WAAW,IAAI;AACxB;AAEA,IAAM,iBAAyC;AAAA,EAC7C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAcO,SAAS,iBAAiB;AAAA,EAC/B,SAAS;AAAA,EACT;AAAA,EACA,QAAQ;AAAA,EACR;AACF,GAA0B;AACxB,QAAM,UAAU,gBAAgB,oBAAoB;AAEpD,SACE,gBAAAA,MAAC,SAAI,WAAU,aACb;AAAA,oBAAAA,MAAC,SACC;AAAA,sBAAAD,KAAC,QAAG,WAAU,qCAAqC,iBAAM;AAAA,MACzD,gBAAAA,KAAC,OAAE,WAAU,sCACV,yBAAe,MAAM,KAAK,eAAe,SAC5C;AAAA,OACF;AAAA,IAEC,UACC,gBAAAC,MAAC,OAAE,WAAU,iCAAgC;AAAA;AAAA,MAC5B;AAAA,MACf,gBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,MAAM,UAAU,OAAO;AAAA,UACvB,WAAU;AAAA,UAET;AAAA;AAAA,MACH;AAAA,MAAK;AAAA,MAAI;AAAA,OAEX,IACE;AAAA,IAEH;AAAA,KACH;AAEJ;","names":["jsx","jsxs","useState","jsx","jsxs","useState","useState","jsx","jsxs","useState","jsx","jsxs","useState","jsx","jsxs","jsx","jsxs","jsx","jsxs"]}
@@ -0,0 +1,82 @@
1
+ import { b as InvitationFailure } from './types-DxllDyOa.js';
2
+
3
+ /**
4
+ * What became of a claim, in terms the invitee can be told.
5
+ *
6
+ * 'expired' and 'claimed' are kept apart from 'unknown' because only they say
7
+ * the offer was real, which is what tells someone that asking for a new link is
8
+ * worth it rather than doubting the address they were invited at. The three
9
+ * failures match InvitationFailure, so an outcome feeds InvitationNotice
10
+ * directly.
11
+ */
12
+ type ClaimOutcome = "granted" | InvitationFailure | "failed";
13
+ interface ClaimInvitationOptions {
14
+ /** Absolute URL of the endpoint that redeems a token. */
15
+ endpoint: string;
16
+ token: string;
17
+ /** The account the app just created, which the grant is attached to. */
18
+ externalUserId: string;
19
+ /** Sent as the Authorization bearer — typically the app's API key. */
20
+ apiKey?: string;
21
+ /** Merged into the request body, for backends wanting more than the token. */
22
+ extra?: Record<string, unknown>;
23
+ /** Headers merged last, so a caller can pass a cookie-based credential. */
24
+ headers?: Record<string, string>;
25
+ /** Bounds the call so a slow API never stalls the sign-in response. */
26
+ timeoutMs?: number;
27
+ }
28
+ /**
29
+ * Redeems an invitation token for a user who has just signed in, turning the
30
+ * offer into a grant on their account.
31
+ *
32
+ * Why this belongs on the SERVER, on the auth callback rather than in the page:
33
+ * the invitation link lands on /register?invite=<token>, but the sign-up that
34
+ * follows can complete through any of three flows (password + OTP, OAuth
35
+ * redirect, email verification), and only two of them return to the page that
36
+ * held the token. Claiming where the session is established covers every flow
37
+ * with one code path.
38
+ *
39
+ * Best-effort by design: a sign-in must never fail because an invitation could
40
+ * not be redeemed. A failed claim leaves the invitation unclaimed and the user
41
+ * on their default tier — recoverable by following the link again, since a
42
+ * refused claim consumes nothing.
43
+ */
44
+ declare function claimInvitation({ endpoint, token, externalUserId, apiKey, extra, headers, timeoutMs, }: ClaimInvitationOptions): Promise<ClaimOutcome>;
45
+ /**
46
+ * Extracts the invitation token from an auth request.
47
+ *
48
+ * The token lives on the page the invitee landed on (/register?invite=…), never
49
+ * on the auth endpoints themselves, so it has to be recovered from the request
50
+ * that completes the sign-up. Two sources, because no single one covers every
51
+ * flow: the URL, for the OAuth callback reached through a redirect whose query
52
+ * string the app controls; and the Referer, for the password and OTP flows,
53
+ * which are XHR calls issued BY that page and therefore carry it.
54
+ *
55
+ * Reading it per-request keeps the claim stateless: nothing associates a
56
+ * browser with a pending invitation, and a request with no token claims
57
+ * nothing. A malformed Referer is ignored rather than thrown on — it is
58
+ * attacker-controlled input on a best-effort path.
59
+ */
60
+ declare function inviteTokenFrom(request: Request, param?: string): string | null;
61
+ /**
62
+ * Whether this request is the one that just created a usable account — the
63
+ * moment to provision, claim an invitation, or greet someone. Matching on the
64
+ * path rather than on a response body keeps it flow-agnostic: the three
65
+ * sign-up flows return three different shapes.
66
+ */
67
+ declare function completesSignup(pathname: string): boolean;
68
+ /**
69
+ * Carries a failed claim to the next page. The claim happens inside an auth
70
+ * response nobody renders, so its result would otherwise reach only the server
71
+ * log — leaving an invitee on the default tier with no idea their link had
72
+ * lapsed. Short-lived and readable by the page, which reports it and clears it.
73
+ */
74
+ declare function invitationOutcomeCookie(outcome: ClaimOutcome, name?: string): string;
75
+ /**
76
+ * Whether an outcome is one the invitee should be shown a reason for.
77
+ * 'failed' is excluded: it means the call did not complete, so the offer may
78
+ * still be good and telling someone their invitation is invalid would be wrong.
79
+ */
80
+ declare function isInvitationFailure(outcome: ClaimOutcome): outcome is InvitationFailure;
81
+
82
+ export { type ClaimOutcome as C, type ClaimInvitationOptions as a, completesSignup as b, claimInvitation as c, invitationOutcomeCookie as d, inviteTokenFrom as e, isInvitationFailure as i };
@@ -0,0 +1,13 @@
1
+ import { Auth, BetterAuthOptions } from 'better-auth';
2
+ import { c as PlatformAuthConfig } from './types-DxllDyOa.js';
3
+ export { g as PlatformSession, h as PlatformSessionData, i as PlatformUser } from './types-DxllDyOa.js';
4
+ export { a as ClaimInvitationOptions, C as ClaimOutcome, c as claimInvitation, b as completesSignup, d as invitationOutcomeCookie, e as inviteTokenFrom, i as isInvitationFailure } from './invitation-CzfLna7q.js';
5
+
6
+ /**
7
+ * Creates a Better Auth instance with platform defaults.
8
+ * Each app calls this with its own config (DB, secret, providers, plugins).
9
+ */
10
+ declare function createPlatformAuth(config: PlatformAuthConfig): Auth<BetterAuthOptions>;
11
+ type PlatformAuth = ReturnType<typeof createPlatformAuth>;
12
+
13
+ export { type PlatformAuth, createPlatformAuth };
package/dist/server.js ADDED
@@ -0,0 +1,132 @@
1
+ import {
2
+ claimInvitation,
3
+ completesSignup,
4
+ invitationOutcomeCookie,
5
+ inviteTokenFrom,
6
+ isInvitationFailure
7
+ } from "./chunk-73BHM4PZ.js";
8
+
9
+ // src/server.ts
10
+ import { betterAuth, APIError } from "better-auth";
11
+ import { emailOTP, admin } from "better-auth/plugins";
12
+ var DEFAULT_EMAIL_SUBJECTS = {
13
+ "email-verification": "Verify your account",
14
+ "forget-password": "Reset your password",
15
+ "sign-in": "Your sign-in code"
16
+ };
17
+ function defaultRenderOtpEmail(otp) {
18
+ return `
19
+ <div style="font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px">
20
+ <h2 style="font-size:20px;font-weight:600;margin-bottom:16px">Your verification code</h2>
21
+ <p style="color:#555;margin-bottom:24px">Use the code below to continue. It expires in 5 minutes.</p>
22
+ <div style="background:#f5f5f5;border-radius:8px;padding:24px;text-align:center;letter-spacing:8px;font-size:32px;font-weight:700">
23
+ ${otp}
24
+ </div>
25
+ <p style="color:#999;font-size:12px;margin-top:24px">If you didn't request this, you can safely ignore this email.</p>
26
+ </div>
27
+ `;
28
+ }
29
+ function createPlatformAuth(config) {
30
+ const {
31
+ database,
32
+ baseURL,
33
+ secret,
34
+ appName,
35
+ mailer,
36
+ google,
37
+ github,
38
+ plugins = [],
39
+ betaMode = false,
40
+ isInvited,
41
+ emailSubjects,
42
+ renderOtpEmail
43
+ } = config;
44
+ const subjects = { ...DEFAULT_EMAIL_SUBJECTS, ...emailSubjects };
45
+ const renderEmail = renderOtpEmail ?? defaultRenderOtpEmail;
46
+ return betterAuth({
47
+ database,
48
+ baseURL,
49
+ secret,
50
+ emailAndPassword: {
51
+ enabled: true,
52
+ requireEmailVerification: true
53
+ },
54
+ // Never auto-merge a social identity into an existing account by matching
55
+ // email. Better Auth links by default (email-verified providers are trusted),
56
+ // so signing in with Google/GitHub on an email already registered would fold
57
+ // that identity into the existing account. We keep each sign-in method its
58
+ // own account: a social login on a taken email is refused, not linked.
59
+ account: {
60
+ accountLinking: {
61
+ enabled: false
62
+ }
63
+ },
64
+ hooks: {
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ before: async (ctx) => {
67
+ if (!betaMode) return;
68
+ if (ctx.path !== "/sign-up/email") return;
69
+ const body = ctx.body;
70
+ const email = body?.email;
71
+ const inviteToken = body?.inviteToken;
72
+ if (email && inviteToken && isInvited) {
73
+ const ok = await isInvited(email, inviteToken);
74
+ if (ok) return;
75
+ }
76
+ throw new APIError("FORBIDDEN", {
77
+ message: "Registration is invite-only during the private beta."
78
+ });
79
+ }
80
+ },
81
+ plugins: [
82
+ emailOTP({
83
+ async sendVerificationOTP({ email, otp, type }) {
84
+ const subject = subjects[type] ? `${subjects[type]} - ${appName}` : `Your ${appName} code`;
85
+ const html = renderEmail(otp, type);
86
+ if (mailer) {
87
+ await mailer({
88
+ to: email,
89
+ subject,
90
+ html,
91
+ type,
92
+ otp
93
+ });
94
+ return;
95
+ }
96
+ console.warn(
97
+ `[EMAIL] No mailer configured \u2014 logging OTP to stdout for ${email} (${type}): ${otp}`
98
+ );
99
+ },
100
+ otpLength: 6,
101
+ expiresIn: 300,
102
+ overrideDefaultEmailVerification: true
103
+ }),
104
+ admin(),
105
+ ...plugins
106
+ // app-specific plugins (e.g. tanstackStartCookies)
107
+ ],
108
+ socialProviders: {
109
+ ...google ? {
110
+ google: {
111
+ clientId: google.clientId,
112
+ clientSecret: google.clientSecret
113
+ }
114
+ } : {},
115
+ ...github ? {
116
+ github: {
117
+ clientId: github.clientId,
118
+ clientSecret: github.clientSecret
119
+ }
120
+ } : {}
121
+ }
122
+ });
123
+ }
124
+ export {
125
+ claimInvitation,
126
+ completesSignup,
127
+ createPlatformAuth,
128
+ invitationOutcomeCookie,
129
+ inviteTokenFrom,
130
+ isInvitationFailure
131
+ };
132
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { betterAuth, APIError, type Auth, type BetterAuthOptions } from \"better-auth\"\nimport { emailOTP, admin } from \"better-auth/plugins\"\nimport type { PlatformAuthConfig, PlatformAuthMailerType } from \"./types\"\n\nconst DEFAULT_EMAIL_SUBJECTS: Record<string, string> = {\n \"email-verification\": \"Verify your account\",\n \"forget-password\": \"Reset your password\",\n \"sign-in\": \"Your sign-in code\",\n}\n\nfunction defaultRenderOtpEmail(otp: string): string {\n return `\n <div style=\"font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px\">\n <h2 style=\"font-size:20px;font-weight:600;margin-bottom:16px\">Your verification code</h2>\n <p style=\"color:#555;margin-bottom:24px\">Use the code below to continue. It expires in 5 minutes.</p>\n <div style=\"background:#f5f5f5;border-radius:8px;padding:24px;text-align:center;letter-spacing:8px;font-size:32px;font-weight:700\">\n ${otp}\n </div>\n <p style=\"color:#999;font-size:12px;margin-top:24px\">If you didn't request this, you can safely ignore this email.</p>\n </div>\n `\n}\n\n/**\n * Creates a Better Auth instance with platform defaults.\n * Each app calls this with its own config (DB, secret, providers, plugins).\n */\nexport function createPlatformAuth(\n config: PlatformAuthConfig,\n): Auth<BetterAuthOptions> {\n const {\n database,\n baseURL,\n secret,\n appName,\n mailer,\n google,\n github,\n plugins = [],\n betaMode = false,\n isInvited,\n emailSubjects,\n renderOtpEmail,\n } = config\n\n const subjects = { ...DEFAULT_EMAIL_SUBJECTS, ...emailSubjects }\n const renderEmail = renderOtpEmail ?? defaultRenderOtpEmail\n\n // The concrete instance type (with email-otp/admin plugins) is widened to\n // the base Auth type so the published .d.ts stays portable (inferring the\n // full plugin type triggers TS2742 — it can't be named without a zod ref).\n // The admin() plugin's user.role field is re-exposed via module augmentation\n // below, so consumers (e.g. transcript-web me.ts) still see session.user.role.\n return betterAuth({\n database,\n baseURL,\n secret,\n emailAndPassword: {\n enabled: true,\n requireEmailVerification: true,\n },\n // Never auto-merge a social identity into an existing account by matching\n // email. Better Auth links by default (email-verified providers are trusted),\n // so signing in with Google/GitHub on an email already registered would fold\n // that identity into the existing account. We keep each sign-in method its\n // own account: a social login on a taken email is refused, not linked.\n account: {\n accountLinking: {\n enabled: false,\n },\n },\n hooks: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n before: async (ctx: any) => {\n if (!betaMode) return\n if (ctx.path !== \"/sign-up/email\") return\n const body = ctx.body as { email?: string; inviteToken?: string } | undefined\n const email = body?.email\n const inviteToken = body?.inviteToken\n if (email && inviteToken && isInvited) {\n const ok = await isInvited(email, inviteToken)\n if (ok) return\n }\n throw new APIError(\"FORBIDDEN\", {\n message: \"Registration is invite-only during the private beta.\",\n })\n },\n },\n plugins: [\n emailOTP({\n async sendVerificationOTP({ email, otp, type }) {\n const subject = subjects[type]\n ? `${subjects[type]} - ${appName}`\n : `Your ${appName} code`\n const html = renderEmail(otp, type as PlatformAuthMailerType)\n\n if (mailer) {\n await mailer({\n to: email,\n subject,\n html,\n type: type as PlatformAuthMailerType,\n otp,\n })\n return\n }\n\n console.warn(\n `[EMAIL] No mailer configured — logging OTP to stdout for ${email} (${type}): ${otp}`,\n )\n },\n otpLength: 6,\n expiresIn: 300,\n overrideDefaultEmailVerification: true,\n }),\n admin(),\n ...plugins, // app-specific plugins (e.g. tanstackStartCookies)\n ],\n socialProviders: {\n ...(google\n ? {\n google: {\n clientId: google.clientId,\n clientSecret: google.clientSecret,\n },\n }\n : {}),\n ...(github\n ? {\n github: {\n clientId: github.clientId,\n clientSecret: github.clientSecret,\n },\n }\n : {}),\n },\n }) as unknown as Auth<BetterAuthOptions>\n}\n\nexport type PlatformAuth = ReturnType<typeof createPlatformAuth>\n\n// Re-export the session contract from /server so consumers that import the\n// auth factory can type api.getSession() without a second import path.\nexport type {\n PlatformUser,\n PlatformSession,\n PlatformSessionData,\n} from \"./types\"\n\n// Invitation claiming runs on the auth callback, where the session is\n// established — the one place every sign-up flow passes through.\nexport {\n claimInvitation,\n completesSignup,\n invitationOutcomeCookie,\n inviteTokenFrom,\n isInvitationFailure,\n} from \"./invitation\"\nexport type { ClaimOutcome, ClaimInvitationOptions } from \"./invitation\"\n"],"mappings":";;;;;;;;;AAAA,SAAS,YA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AAS,IAAI,IACzB,GAAG,SAAS,IAAI,CAAC,MAAM,OAAO,KAC9B,QAAQ,OAAO;AACnB,gBAAM,OAAO,YAAY,KAAK,IAA8B;AAE5D,cAAI,QAAQ;AACV,kBAAM,OAAO;AAAA,cACX,IAAI;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF,CAAC;AACD;AAAA,UACF;AAEA,kBAAQ;AAAA,YACN,iEAA4D,KAAK,KAAK,IAAI,MAAM,GAAG;AAAA,UACrF;AAAA,QACF;AAAA,QACA,WAAW;AAAA,QACX,WAAW;AAAA,QACX,kCAAkC;AAAA,MACpC,CAAC;AAAA,MACD,MAAM;AAAA,MACN,GAAG;AAAA;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,MACf,GAAI,SACA;AAAA,QACE,QAAQ;AAAA,UACN,UAAU,OAAO;AAAA,UACjB,cAAc,OAAO;AAAA,QACvB;AAAA,MACF,IACA,CAAC;AAAA,MACL,GAAI,SACA;AAAA,QACE,QAAQ;AAAA,UACN,UAAU,OAAO;AAAA,UACjB,cAAc,OAAO;AAAA,QACvB;AAAA,MACF,IACA,CAAC;AAAA,IACP;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,196 @@
1
+ import { BetterAuthOptions } from 'better-auth';
2
+
3
+ /**
4
+ * Session user shape exposed by the platform auth instance.
5
+ *
6
+ * The instance returned by {@link createPlatformAuth} is widened to the base
7
+ * `Auth` type so the published `.d.ts` stays portable (inferring the full
8
+ * plugin-augmented type triggers TS2742). That widening hides the fields the
9
+ * email-otp/admin plugins add at runtime — notably `role` from `admin()`.
10
+ *
11
+ * This is the hand-maintained contract for what `api.getSession()` actually
12
+ * returns. Consumers cast the session to {@link PlatformSession} to read these
13
+ * fields with types. Keep it in sync with the enabled plugins.
14
+ */
15
+ interface PlatformUser {
16
+ id: string;
17
+ email: string;
18
+ emailVerified: boolean;
19
+ name: string;
20
+ image?: string | null;
21
+ createdAt: Date;
22
+ updatedAt: Date;
23
+ /** From the admin() plugin. Absent until a role is assigned. */
24
+ role?: string | null;
25
+ /** From the admin() plugin. */
26
+ banned?: boolean | null;
27
+ }
28
+ interface PlatformSessionData {
29
+ id: string;
30
+ userId: string;
31
+ expiresAt: Date;
32
+ token: string;
33
+ createdAt: Date;
34
+ updatedAt: Date;
35
+ ipAddress?: string | null;
36
+ userAgent?: string | null;
37
+ }
38
+ /** Return shape of `auth.api.getSession()` for platform apps. */
39
+ interface PlatformSession {
40
+ user: PlatformUser;
41
+ session: PlatformSessionData;
42
+ }
43
+ type PlatformAuthMailerType = "email-verification" | "forget-password" | "sign-in" | "change-email";
44
+ interface PlatformAuthMailerArgs {
45
+ /** Recipient address */
46
+ to: string;
47
+ /** Pre-rendered subject line */
48
+ subject: string;
49
+ /** Pre-rendered HTML body */
50
+ html: string;
51
+ /** Better Auth verification kind */
52
+ type: PlatformAuthMailerType;
53
+ /** The OTP value, in case the consumer wants to render its own template */
54
+ otp: string;
55
+ }
56
+ type PlatformAuthMailer = (args: PlatformAuthMailerArgs) => Promise<void>;
57
+ interface PlatformAuthConfig {
58
+ /** PostgreSQL connection pool or connection string */
59
+ database: BetterAuthOptions["database"];
60
+ /** Base URL for Better Auth callbacks (e.g. http://localhost:3001) */
61
+ baseURL: string;
62
+ /** Secret for signing sessions */
63
+ secret: string;
64
+ /** Application name (used in emails) */
65
+ appName: string;
66
+ /**
67
+ * Transactional mailer. Receives the fully-rendered subject and HTML body
68
+ * and is responsible for pushing the message onto the wire (e.g. via the
69
+ * @digstack/spore-sdk, SES, postfix, …). When omitted, OTPs are logged to
70
+ * stdout — useful in dev/test, useless in production.
71
+ */
72
+ mailer?: PlatformAuthMailer;
73
+ /** Google OAuth config (omit to disable) */
74
+ google?: {
75
+ clientId: string;
76
+ clientSecret: string;
77
+ };
78
+ /** GitHub OAuth config (omit to disable) */
79
+ github?: {
80
+ clientId: string;
81
+ clientSecret: string;
82
+ };
83
+ /**
84
+ * Override the OTP email subject line per verification type. Merged over
85
+ * the platform defaults — provide only the keys you want to change. The
86
+ * resulting subject is suffixed with ` - ${appName}` like the defaults.
87
+ */
88
+ emailSubjects?: Partial<Record<PlatformAuthMailerType, string>>;
89
+ /**
90
+ * Override the OTP email HTML renderer. Receives the OTP code and the
91
+ * verification type, returns the HTML body. When omitted, the platform's
92
+ * default branded template is used.
93
+ */
94
+ renderOtpEmail?: (otp: string, type: PlatformAuthMailerType) => string;
95
+ /** Additional Better Auth plugins to append */
96
+ plugins?: BetterAuthOptions["plugins"];
97
+ /** Enable private beta mode (blocks public registration) */
98
+ betaMode?: boolean;
99
+ /** Check if an email+token pair has been invited (required when betaMode is true) */
100
+ isInvited?: (email: string, inviteToken: string) => Promise<boolean>;
101
+ }
102
+ interface PlatformAuthClientConfig {
103
+ /** Base URL override (defaults to window.location.origin in browser) */
104
+ baseURL?: string;
105
+ /** Additional client plugins */
106
+ plugins?: any[];
107
+ }
108
+ interface VerifyEmailFormProps {
109
+ /** Email to verify */
110
+ email: string;
111
+ /** Callback on successful verification */
112
+ onSuccess?: () => void;
113
+ /** URL to navigate to on success */
114
+ successUrl?: string;
115
+ /** Auth client instance */
116
+ authClient: any;
117
+ }
118
+ /** Why an invitation link did not work, as far as the invitee needs to know. */
119
+ type InvitationFailure = "expired" | "claimed" | "unknown";
120
+ interface InvitationNoticeProps {
121
+ reason?: InvitationFailure;
122
+ /** Defaults to contact@ the apex domain the app is served from. */
123
+ supportEmail?: string;
124
+ title?: string;
125
+ /** Rendered under the contact line — typically a link back to the site. */
126
+ action?: React.ReactNode;
127
+ }
128
+ interface LoginFormProps {
129
+ /** Callback once the session cookie is set and the core token minted */
130
+ onSuccess?: () => void;
131
+ /** Link to the registration page */
132
+ registerUrl?: string;
133
+ /** Link to the password recovery page */
134
+ forgotPasswordUrl?: string;
135
+ /**
136
+ * Where Better Auth sends the browser back after a social sign-in. Social
137
+ * buttons are only rendered when at least one provider is passed.
138
+ */
139
+ socialCallbackUrl?: string;
140
+ /** Social providers to offer, in display order */
141
+ socialProviders?: Array<"google" | "github">;
142
+ /**
143
+ * Endpoint trading the fresh better-auth session for the short-lived EdDSA
144
+ * token the Go core verifies. Called after a successful password sign-in;
145
+ * pass null to skip when the app has no core.
146
+ */
147
+ coreTokenUrl?: string | null;
148
+ /** Auth client instance */
149
+ authClient: any;
150
+ }
151
+ interface RegisterFormProps {
152
+ /** Callback on successful sign-up, receives the email to verify */
153
+ onSuccess?: (email: string) => void;
154
+ /** Link to the login page */
155
+ loginUrl?: string;
156
+ /** Rendered under the submit button — typically terms and privacy links */
157
+ legal?: React.ReactNode;
158
+ /** Where Better Auth sends the browser back after a social sign-up */
159
+ socialCallbackUrl?: string;
160
+ /** Social providers to offer, in display order */
161
+ socialProviders?: Array<"google" | "github">;
162
+ /** Auth client instance */
163
+ authClient: any;
164
+ }
165
+ interface ForgotPasswordFormProps {
166
+ /** Callback on successful OTP send, receives the email */
167
+ onSuccess?: (email: string) => void;
168
+ /** Link to login page */
169
+ loginUrl?: string;
170
+ /** Auth client instance */
171
+ authClient: any;
172
+ }
173
+ interface ResetPasswordFormProps {
174
+ /** Email address to reset password for */
175
+ email: string;
176
+ /** Callback on successful password reset */
177
+ onSuccess?: () => void;
178
+ /** Link to login page */
179
+ loginUrl?: string;
180
+ /** Auth client instance */
181
+ authClient: any;
182
+ }
183
+ interface AuthLayoutProps {
184
+ /** Logo element to display at the top */
185
+ logo?: React.ReactNode;
186
+ /** Page title */
187
+ title: string;
188
+ /** Subtitle below the title */
189
+ subtitle?: string;
190
+ /** Content to render inside the card */
191
+ children: React.ReactNode;
192
+ /** Footer content below the card (e.g. legal links) */
193
+ footer?: React.ReactNode;
194
+ }
195
+
196
+ export type { AuthLayoutProps as A, ForgotPasswordFormProps as F, InvitationNoticeProps as I, LoginFormProps as L, PlatformAuthClientConfig as P, RegisterFormProps as R, VerifyEmailFormProps as V, ResetPasswordFormProps as a, InvitationFailure as b, PlatformAuthConfig as c, PlatformAuthMailer as d, PlatformAuthMailerArgs as e, PlatformAuthMailerType as f, PlatformSession as g, PlatformSessionData as h, PlatformUser as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lalternative/auth",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Shared Better Auth wrapper for L'Alternative apps (server + React client + auth UI)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -25,7 +25,8 @@
25
25
  "scripts": {
26
26
  "build": "tsup",
27
27
  "dev": "tsup --watch",
28
- "typecheck": "tsc --noEmit"
28
+ "typecheck": "tsc --noEmit",
29
+ "prepublishOnly": "pnpm build"
29
30
  },
30
31
  "peerDependencies": {
31
32
  "better-auth": ">=1.4.0",