"use client"; import { useState } from "react"; import Link from "next/link"; import { signIn } from "next-auth/react"; /** * Vibn sign-in / sign-up screen. * * Ported from design-templates/VIBN (2) (auth.css + signin/signup.jsx). Email + * password is the primary action (custom endpoints at /api/auth/register and * /api/auth/login that create real NextAuth database sessions); Google OAuth is * offered below. Mode is driven by the `?new=1` query param. */ export default function AuthScreen({ mode = "signin", }: { mode?: "signin" | "signup"; }) { const isSignup = mode === "signup"; const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [submitting, setSubmitting] = useState(false); const [googleLoading, setGoogleLoading] = useState(false); const [error, setError] = useState(null); const emailValid = /\S+@\S+\.\S+/.test(email); const canSubmit = emailValid && password.length >= 8 && !submitting; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!canSubmit) return; setError(null); setSubmitting(true); try { const endpoint = isSignup ? "/api/auth/register" : "/api/auth/login"; const res = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify( isSignup ? { email, password, name: name.trim() || undefined } : { email, password }, ), }); const data = await res.json().catch(() => ({})); if (!res.ok) { setError(data.error || "Something went wrong. Please try again."); setSubmitting(false); return; } // Full reload so the session cookie is picked up and AuthFlow routes the // user onward (new account -> /onboarding, returning -> dashboard). window.location.href = "/signin"; } catch { setError("Network error. Please try again."); setSubmitting(false); } }; const handleGoogle = () => { if (googleLoading) return; setGoogleLoading(true); const cb = typeof window !== "undefined" ? window.location.href : "/signin"; signIn("google", { callbackUrl: cb }); }; const trust = isSignup ? ["No credit card", "No homework", "🇨🇦 Built in Canada"] : ["Built in Canada", "Your data stays safe", "No homework"]; return (
vibn Back to home
{isSignup ? "Get started" : "Welcome back"}

{isSignup ? ( <> Create your workspace. ) : ( <> Sign in and keep building. )}

{isSignup ? "Set up your account with an email and password — you'll be building in seconds." : "Pick up right where you left off."}

{isSignup && (
setName(e.target.value)} />
)}
setEmail(e.target.value)} />
setPassword(e.target.value)} />
{error &&
{error}
}
or continue with
{isSignup && (

By continuing you agree to our{" "} Terms and{" "} Privacy Policy.

)}
{isSignup ? ( <> Already have an account? Sign in → ) : ( <> New to Vibn? Create an account → )}
); } function Glows() { return ( <>
); } function TrustStrip({ items }: { items: string[] }) { return (
{items.map((item, i) => ( {i > 0 && ·} {item} ))}
); } function Arrow({ size = 14 }: { size?: number }) { return ( ); } function GoogleIcon({ size = 17 }: { size?: number }) { return ( ); }