Join SnipStash to create, tag, and manage your code snippets.
"use client";
import { useState } from "react";
import { Code2, Eye, EyeOff, Loader2 } from "lucide-react";
import { registerUser } from "@/lib/auth-actions";
// import Link from "next/link";
import Link from "next/link";
export default function RegisterPage() {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false);
async function handleSubmit(e) {
e.preventDefault();
setError("");
setLoading(true);
const formData = new FormData(e.target);
const name = formData.get("name");
const email = formData.get("email");
const password = formData.get("password");
const result = await registerUser({ name, email, password });
if (result?.error) {
setError(result.error);
setLoading(false);
}
}
return (
<div className="flex min-h-screen items-center justify-center px-4">
{/* Background glow */}
<div className="pointer-events-none absolute inset-0 -z-10 overflow-hidden">
<div className="animate-pulse-glow absolute left-1/2 top-1/3 h-[400px] w-[400px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-accent/10 blur-[100px]" />
</div>
<div className="w-full max-w-md">
{/* Logo */}
<div className="mb-8 text-center">
<Link href="/" className="inline-flex items-center gap-2.5">
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-accent/10">
<Code2 className="h-6 w-6 text-accent" />
</div>
<span className="text-2xl font-bold text-foreground">SnipStash</span>
</Link>
<h1 className="mt-6 text-2xl font-bold text-foreground">
Create your account
</h1>
<p className="mt-2 text-sm text-muted-foreground">
Start organizing your code snippets today
</p>
</div>
{/* Form card */}
<div className="rounded-2xl bg-card p-8 ring-1 ring-border/50 shadow-xl shadow-black/5">
<form onSubmit={handleSubmit} className="space-y-5">
{error && (
<div className="rounded-lg bg-red-500/10 px-4 py-3 text-sm text-red-500 ring-1 ring-red-500/20">
{error}
</div>
)}
<div>
<label htmlFor="name" className="block text-sm font-medium text-foreground">
Name
</label>
<input
id="name"
name="name"
type="text"
required
className="mt-1.5 block w-full rounded-xl bg-muted px-4 py-3 text-sm text-foreground placeholder-muted-foreground outline-none ring-1 ring-border/50 transition-all focus:ring-2 focus:ring-accent"
placeholder="Your name"
/>
</div>
<div>
<label htmlFor="email" className="block text-sm font-medium text-foreground">
Email
</label>
<input
id="email"
name="email"
type="email"
required
className="mt-1.5 block w-full rounded-xl bg-muted px-4 py-3 text-sm text-foreground placeholder-muted-foreground outline-none ring-1 ring-border/50 transition-all focus:ring-2 focus:ring-accent"
placeholder="you@example.com"
/>
</div>
<div>
<label htmlFor="password" className="block text-sm font-medium text-foreground">
Password
</label>
<div className="relative mt-1.5">
<input
id="password"
name="password"
type={showPassword ? "text" : "password"}
required
minLength={6}
className="block w-full rounded-xl bg-muted px-4 py-3 pr-11 text-sm text-foreground placeholder-muted-foreground outline-none ring-1 ring-border/50 transition-all focus:ring-2 focus:ring-accent"
placeholder="At least 6 characters"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground transition-colors hover:text-foreground"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
</div>
<button
type="submit"
disabled={loading}
className="flex w-full items-center justify-center gap-2 rounded-xl bg-accent px-4 py-3 text-sm font-semibold text-accent-foreground shadow-lg shadow-accent/25 transition-all duration-300 hover:bg-accent-hover hover:shadow-accent/30 hover:-translate-y-0.5 disabled:opacity-50 disabled:pointer-events-none"
>
{loading ? (
<>
<Loader2 className="h-4 w-4 animate-spin" />
Creating account...
</>
) : (
"Create Account"
)}
</button>
</form>
{/* Divider */}
<div className="my-6 flex items-center gap-3">
<div className="h-px flex-1 bg-border" />
<span className="text-xs text-muted-foreground">or continue with</span>
<div className="h-px flex-1 bg-border" />
</div>
{/* Google OAuth */}
<button
disabled
className="flex w-full items-center justify-center gap-3 rounded-xl px-4 py-3 text-sm font-medium text-foreground ring-1 ring-border/50 transition-all duration-200 hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed"
>
<svg className="h-5 w-5" viewBox="0 0 24 24">
<path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z" fill="#4285F4" />
<path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" />
<path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" fill="#FBBC05" />
<path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" />
</svg>
Google (Coming Soon)
</button>
</div>
{/* Login link */}
<p className="mt-6 text-center text-sm text-muted-foreground">
Already have an account?{" "}
<a href="/login" className="font-medium text-accent transition-colors hover:text-accent-hover">
Sign in
</a>
</p>
</div>
</div>
);
}