Files
periscope/frontend/src/app/(marketing)/sign-in/page.tsx
T
micheleandCursor 8d2b85600f Rebrand Pinscope to Periscope across product and codebase.
Rename the core package to periscopex, update UI/docs/Docker/deploy defaults to periscope.michelebigi.it, and keep legacy version/storage key aliases so existing projects keep working.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 20:02:04 +02:00

87 lines
2.8 KiB
TypeScript

"use client";
import { FormEvent, useState } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { storeAuthToken } from "@/hooks/use-optional-auth";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? "";
export default function SignInPage() {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
async function onSubmit(e: FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
try {
const res = await fetch(`${API_BASE}/api/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password }),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
throw new Error(data.detail || "Sign in failed");
}
storeAuthToken(data.token);
router.replace("/");
router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : "Sign in failed");
} finally {
setBusy(false);
}
}
return (
<div className="mx-auto flex min-h-[70vh] max-w-md flex-col justify-center px-4 py-16">
<h1 className="font-display text-3xl tracking-tight">Sign in</h1>
<p className="mt-2 text-sm text-muted-foreground">
Periscope account for this server. Invite collaborators from a project once they have an account.
</p>
<form onSubmit={onSubmit} className="mt-8 flex flex-col gap-4">
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
autoComplete="email"
required
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
autoComplete="current-password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
<Button type="submit" disabled={busy}>
{busy ? "Signing in…" : "Sign in"}
</Button>
</form>
<p className="mt-6 text-sm text-muted-foreground">
No account?{" "}
<Link href="/sign-up" className="underline underline-offset-4">
Create one
</Link>
</p>
</div>
);
}