2026-01-06 14:46:23 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
2026-01-06 14:59:47 +00:00
|
|
|
import { Mail, Lock, User, ArrowRight, ArrowLeft } from "lucide-react";
|
2026-01-06 14:46:23 +00:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
2026-01-06 14:59:47 +00:00
|
|
|
import { PasswordStrengthMeter, isPasswordValid } from "@/components/auth/PasswordStrengthMeter";
|
|
|
|
|
import { BannerAlert } from "@/components/auth/BannerAlert";
|
|
|
|
|
|
|
|
|
|
type RegistrationState = "form" | "success" | "disabled";
|
2026-01-06 14:46:23 +00:00
|
|
|
|
|
|
|
|
export default function RegisterPage() {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const [name, setName] = useState("");
|
|
|
|
|
const [email, setEmail] = useState("");
|
|
|
|
|
const [password, setPassword] = useState("");
|
|
|
|
|
const [confirmPassword, setConfirmPassword] = useState("");
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
2026-01-06 14:59:47 +00:00
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
const [state, setState] = useState<RegistrationState>("form");
|
|
|
|
|
|
|
|
|
|
const passwordsMatch = password === confirmPassword;
|
|
|
|
|
const canSubmit =
|
|
|
|
|
name.trim() &&
|
|
|
|
|
email.trim() &&
|
|
|
|
|
isPasswordValid(password) &&
|
|
|
|
|
passwordsMatch;
|
2026-01-06 14:46:23 +00:00
|
|
|
|
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
|
|
|
e.preventDefault();
|
2026-01-06 14:59:47 +00:00
|
|
|
setError(null);
|
|
|
|
|
|
|
|
|
|
if (!passwordsMatch) {
|
|
|
|
|
setError("Passwords do not match");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isPasswordValid(password)) {
|
|
|
|
|
setError("Password does not meet requirements");
|
2026-01-06 14:46:23 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2026-01-06 14:59:47 +00:00
|
|
|
|
2026-01-06 14:46:23 +00:00
|
|
|
setIsLoading(true);
|
2026-01-06 14:59:47 +00:00
|
|
|
|
|
|
|
|
// Mock registration - will be replaced with actual API call
|
|
|
|
|
// POST /api/auth/register
|
2026-01-06 14:46:23 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
|
setIsLoading(false);
|
2026-01-06 14:59:47 +00:00
|
|
|
|
|
|
|
|
// Simulate different responses
|
|
|
|
|
const mockResponse = "success" as RegistrationState | "error";
|
|
|
|
|
|
|
|
|
|
if (mockResponse === "disabled") {
|
|
|
|
|
setState("disabled");
|
|
|
|
|
} else if (mockResponse === "error") {
|
|
|
|
|
setError("An error occurred. Please try again.");
|
|
|
|
|
} else {
|
|
|
|
|
setState("success");
|
|
|
|
|
}
|
2026-01-06 14:46:23 +00:00
|
|
|
}, 1000);
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-06 14:59:47 +00:00
|
|
|
// Registration disabled state
|
|
|
|
|
if (state === "disabled") {
|
|
|
|
|
return (
|
|
|
|
|
<div className="auth-card text-center">
|
|
|
|
|
<div className="w-16 h-16 rounded-full bg-warning/10 flex items-center justify-center mx-auto mb-6">
|
|
|
|
|
<Lock className="w-8 h-8 text-warning" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<h1 className="text-2xl font-semibold text-foreground tracking-tight">
|
|
|
|
|
Registration unavailable
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-muted-foreground mt-2 mb-6">
|
|
|
|
|
New account registration is currently invite-only. Please contact your administrator for an invitation.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<Link to="/login">
|
|
|
|
|
<Button variant="outline" className="w-full">
|
|
|
|
|
<ArrowLeft className="w-4 h-4 mr-2" />
|
|
|
|
|
Back to sign in
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Success state - email sent
|
|
|
|
|
if (state === "success") {
|
|
|
|
|
return (
|
|
|
|
|
<div className="auth-card text-center">
|
|
|
|
|
<div className="w-16 h-16 rounded-full bg-success/10 flex items-center justify-center mx-auto mb-6">
|
|
|
|
|
<Mail className="w-8 h-8 text-success" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<h1 className="text-2xl font-semibold text-foreground tracking-tight">
|
|
|
|
|
Check your email
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-muted-foreground mt-2 mb-6">
|
|
|
|
|
We've sent a verification link to <span className="font-medium text-foreground">{email}</span>.
|
|
|
|
|
Click the link to verify your account and get started.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<Link to="/login">
|
|
|
|
|
<Button className="w-full">
|
|
|
|
|
Continue to sign in
|
|
|
|
|
<ArrowRight className="w-4 h-4 ml-2" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<p className="text-sm text-muted-foreground mt-6">
|
|
|
|
|
Didn't receive the email?{" "}
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setState("form")}
|
|
|
|
|
className="text-accent hover:underline font-medium"
|
|
|
|
|
>
|
|
|
|
|
Try again
|
|
|
|
|
</button>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Registration form
|
2026-01-06 14:46:23 +00:00
|
|
|
return (
|
|
|
|
|
<div className="auth-card">
|
|
|
|
|
<div className="text-center mb-8">
|
|
|
|
|
<h1 className="text-2xl font-semibold text-foreground tracking-tight">
|
|
|
|
|
Create your account
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-muted-foreground mt-2">
|
|
|
|
|
Get started with Authy2 in seconds
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-06 14:59:47 +00:00
|
|
|
{error && (
|
|
|
|
|
<BannerAlert
|
|
|
|
|
type="error"
|
|
|
|
|
message={error}
|
|
|
|
|
className="mb-6"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-01-06 14:46:23 +00:00
|
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
|
|
|
<div className="space-y-2">
|
2026-01-06 14:59:47 +00:00
|
|
|
<Label htmlFor="name">Display name</Label>
|
2026-01-06 14:46:23 +00:00
|
|
|
<div className="relative">
|
|
|
|
|
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
|
|
|
<Input
|
|
|
|
|
id="name"
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="John Doe"
|
|
|
|
|
value={name}
|
|
|
|
|
onChange={(e) => setName(e.target.value)}
|
|
|
|
|
className="pl-10"
|
|
|
|
|
required
|
2026-01-06 14:59:47 +00:00
|
|
|
autoComplete="name"
|
2026-01-06 14:46:23 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label htmlFor="email">Email</Label>
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
|
|
|
<Input
|
|
|
|
|
id="email"
|
|
|
|
|
type="email"
|
|
|
|
|
placeholder="you@example.com"
|
|
|
|
|
value={email}
|
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
|
|
|
className="pl-10"
|
|
|
|
|
required
|
2026-01-06 14:59:47 +00:00
|
|
|
autoComplete="email"
|
2026-01-06 14:46:23 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label htmlFor="password">Password</Label>
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
|
|
|
<Input
|
|
|
|
|
id="password"
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="••••••••"
|
|
|
|
|
value={password}
|
|
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
|
|
|
className="pl-10"
|
|
|
|
|
required
|
2026-01-06 14:59:47 +00:00
|
|
|
autoComplete="new-password"
|
2026-01-06 14:46:23 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
2026-01-06 14:59:47 +00:00
|
|
|
<PasswordStrengthMeter password={password} />
|
2026-01-06 14:46:23 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label htmlFor="confirmPassword">Confirm password</Label>
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
|
|
|
<Input
|
|
|
|
|
id="confirmPassword"
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="••••••••"
|
|
|
|
|
value={confirmPassword}
|
|
|
|
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
|
|
|
className="pl-10"
|
|
|
|
|
required
|
2026-01-06 14:59:47 +00:00
|
|
|
autoComplete="new-password"
|
2026-01-06 14:46:23 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
2026-01-06 14:59:47 +00:00
|
|
|
{confirmPassword && !passwordsMatch && (
|
|
|
|
|
<p className="text-xs text-destructive">Passwords do not match</p>
|
|
|
|
|
)}
|
2026-01-06 14:46:23 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-01-06 14:59:47 +00:00
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
className="w-full"
|
|
|
|
|
disabled={isLoading || !canSubmit}
|
|
|
|
|
>
|
2026-01-06 14:46:23 +00:00
|
|
|
{isLoading ? (
|
|
|
|
|
"Creating account..."
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
Create account
|
|
|
|
|
<ArrowRight className="w-4 h-4 ml-2" />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<p className="text-center text-sm text-muted-foreground mt-6">
|
|
|
|
|
Already have an account?{" "}
|
|
|
|
|
<Link to="/login" className="text-accent hover:underline font-medium">
|
|
|
|
|
Sign in
|
|
|
|
|
</Link>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p className="text-center text-xs text-muted-foreground mt-4">
|
|
|
|
|
By creating an account, you agree to our{" "}
|
2026-01-06 14:59:47 +00:00
|
|
|
<Link to="/terms" className="underline hover:text-foreground">
|
2026-01-06 14:46:23 +00:00
|
|
|
Terms of Service
|
|
|
|
|
</Link>{" "}
|
|
|
|
|
and{" "}
|
2026-01-06 14:59:47 +00:00
|
|
|
<Link to="/privacy" className="underline hover:text-foreground">
|
2026-01-06 14:46:23 +00:00
|
|
|
Privacy Policy
|
|
|
|
|
</Link>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|