Spaces:
Sleeping
Sleeping
File size: 4,969 Bytes
b0798af | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | "use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { AudioLines, ArrowRight, Leaf } from "lucide-react";
import { api } from "@/lib/api/apiClient";
export default function AuthForm({ signup = false }: { signup?: boolean }) {
const router = useRouter(),
[email, setEmail] = useState(""),
[password, setPassword] = useState(""),
[name, setName] = useState(""),
[username, setUsername] = useState(""),
[error, setError] = useState(""),
[busy, setBusy] = useState(false);
return (
<div className="auth-page">
<Link href="/" className="brand">
<span className="brand-mark">
<AudioLines size={22} />
</span>
stillwave.
</Link>
<div className="auth-grid">
<div className="auth-copy">
<span className="eyebrow">YOUR MUSIC. YOUR MOMENT.</span>
<h1>
A little less noise.
<br />A little more you.
</h1>
<p>
A thoughtful home for the songs you love, and the ones you haven’t
met yet.
</p>
<div className="auth-decoration">
<div className="hero-disc">
<div className="disc-grooves" />
<div className="disc-label">
<Leaf size={30} />
<span>STILLWAVE</span>
</div>
</div>
</div>
</div>
<form
className="auth-card"
onSubmit={async (e) => {
e.preventDefault();
setBusy(true);
setError("");
try {
if (signup)
await api.signup({
email: email.trim(),
password,
username: username.trim(),
display_name: name.trim(),
});
else await api.login({ email: email.trim(), password });
await api.getMe();
router.replace("/");
router.refresh();
} catch (e) {
setError((e as Error).message);
} finally {
setBusy(false);
}
}}
>
<span className="eyebrow">
{signup ? "COME ON IN" : "WELCOME BACK"}
</span>
<h2>
{signup ? "Make yourself at home." : "Your music is waiting."}
</h2>
<p>
{signup
? "Create your own quiet corner."
: "Sign in and pick up where you left off."}
</p>
{error && (
<div className="notice error" role="alert">
{error}
</div>
)}
{signup && (
<>
<label className="field">
Your name
<input
autoComplete="name"
required
maxLength={100}
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="What should we call you?"
/>
</label>
<label className="field">
Username
<input
autoComplete="username"
required
minLength={3}
maxLength={30}
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="A name of your own"
/>
</label>
</>
)}
<label className="field">
Email address
<input
type="email"
autoComplete="email"
required
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="you@example.com"
/>
</label>
<label className="field">
Password
<input
type="password"
autoComplete={signup ? "new-password" : "current-password"}
required
minLength={signup ? 8 : 1}
maxLength={72}
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder={signup ? "At least 8 characters" : "Your password"}
/>
</label>
<button className="button full" disabled={busy}>
{busy ? "Just a moment…" : signup ? "Create account" : "Sign in"}
<ArrowRight size={17} />
</button>
<p className="auth-switch">
{signup ? "Already at home here?" : "New to Stillwave?"}{" "}
<Link href={signup ? "/login" : "/signup"}>
{signup ? "Sign in" : "Make an account"}
</Link>
</p>
</form>
</div>
<p className="auth-footer">Take your time. The music will be here.</p>
</div>
);
}
|