765 lines
31 KiB
JavaScript
765 lines
31 KiB
JavaScript
import { writeFileSync, mkdirSync } from "fs";
|
|
|
|
// ─── Updated login/page.tsx ──────────────────────────────────────────────────
|
|
writeFileSync("app/login/page.tsx", `"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
import { Suspense, useState } from "react";
|
|
import { PageSchema } from "../../components/page-schema";
|
|
import { SiteFooter } from "../../components/site-footer";
|
|
import { SiteHeader } from "../../components/site-header";
|
|
import { defaultFaqs } from "../../data/faq";
|
|
import { siteInfo } from "../../data/site";
|
|
import { storeAuthTokens } from "../../lib/api";
|
|
|
|
type ApiResponse<T> = {
|
|
data: T;
|
|
meta: { timestamp: string; version: "v1" };
|
|
error: null | { message: string; code?: string };
|
|
};
|
|
|
|
type AuthData = {
|
|
user: { id: string; email: string; fullName?: string; emailVerified?: boolean };
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
requiresTwoFactor?: boolean;
|
|
};
|
|
|
|
function LoginForm() {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
const nextPath = searchParams.get("next") ?? "/app";
|
|
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [totpToken, setTotpToken] = useState("");
|
|
const [requiresTwoFactor, setRequiresTwoFactor] = useState(false);
|
|
const [status, setStatus] = useState<string>("");
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const onSubmit = async (event: React.FormEvent) => {
|
|
event.preventDefault();
|
|
setStatus("Signing in...");
|
|
setIsError(false);
|
|
try {
|
|
const res = await fetch("/api/auth/login", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email, password, ...(requiresTwoFactor ? { totpToken } : {}) }),
|
|
});
|
|
const payload = (await res.json()) as ApiResponse<AuthData>;
|
|
if (!res.ok || payload.error) {
|
|
setStatus(payload.error?.message ?? "Login failed.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
|
|
if (payload.data.requiresTwoFactor) {
|
|
setRequiresTwoFactor(true);
|
|
setStatus("Enter the code from your authenticator app.");
|
|
return;
|
|
}
|
|
|
|
storeAuthTokens({
|
|
accessToken: payload.data.accessToken,
|
|
refreshToken: payload.data.refreshToken,
|
|
user: payload.data.user,
|
|
});
|
|
setStatus(\`Welcome back, \${payload.data.user.email}\`);
|
|
router.push(nextPath);
|
|
} catch {
|
|
setStatus("Login failed. Please try again.");
|
|
setIsError(true);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<form className="space-y-6" onSubmit={onSubmit}>
|
|
<div>
|
|
<label htmlFor="email" className="block text-sm font-medium text-foreground">
|
|
Email address
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="email" name="email" type="email" autoComplete="email" required
|
|
value={email} onChange={(e) => setEmail(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor="password" className="block text-sm font-medium text-foreground">
|
|
Password
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="password" name="password" type="password" autoComplete="current-password" required
|
|
value={password} onChange={(e) => setPassword(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{requiresTwoFactor && (
|
|
<div>
|
|
<label htmlFor="totp" className="block text-sm font-medium text-foreground">
|
|
Authenticator Code
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="totp" name="totp" type="text" inputMode="numeric" maxLength={6}
|
|
placeholder="6-digit code" autoComplete="one-time-code" required
|
|
value={totpToken} onChange={(e) => setTotpToken(e.target.value.replace(/\\D/g, ""))}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all tracking-widest text-center"
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div>
|
|
<button
|
|
type="submit"
|
|
className="flex w-full justify-center rounded-lg border border-transparent bg-primary py-2.5 px-4 text-sm font-bold text-primary-foreground shadow-sm hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 transition-all hover:-translate-y-0.5"
|
|
>
|
|
{requiresTwoFactor ? "Verify" : "Sign in"}
|
|
</button>
|
|
</div>
|
|
|
|
<div className="text-center">
|
|
<Link href="/forgot-password" className="text-sm text-muted-foreground hover:text-primary transition-colors">
|
|
Forgot your password?
|
|
</Link>
|
|
</div>
|
|
|
|
{status && (
|
|
<div className={\`mt-4 rounded-lg p-4 \${isError ? "bg-red-500/10 border border-red-500/20" : "bg-accent/10 border border-accent/20"}\`}>
|
|
<p className="text-sm font-medium text-center">{status}</p>
|
|
</div>
|
|
)}
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export default function LoginPage() {
|
|
const schema = [
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "WebPage",
|
|
name: "LedgerOne Login",
|
|
description: "Sign in to LedgerOne to access your audit-ready ledger.",
|
|
url: \`\${siteInfo.url}/login\`,
|
|
},
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "FAQPage",
|
|
mainEntity: defaultFaqs.map((item) => ({
|
|
"@type": "Question",
|
|
name: item.question,
|
|
acceptedAnswer: { "@type": "Answer", text: item.answer },
|
|
})),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background font-sans text-foreground">
|
|
<SiteHeader />
|
|
<div className="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8 mt-16 relative">
|
|
<div className="absolute inset-0 mesh-gradient -z-10 opacity-30" />
|
|
<div className="sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="flex justify-center">
|
|
<div className="h-12 w-12 rounded-xl bg-primary flex items-center justify-center text-primary-foreground font-bold text-xl shadow-glow-teal">
|
|
L1
|
|
</div>
|
|
</div>
|
|
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-foreground">
|
|
Sign in to your account
|
|
</h2>
|
|
<p className="mt-2 text-center text-sm text-muted-foreground">
|
|
Or{" "}
|
|
<Link href="/register" className="font-medium text-primary hover:text-primary/80 transition-colors">
|
|
start your 14-day free trial
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="glass-panel py-8 px-4 shadow-xl sm:rounded-xl sm:px-10">
|
|
<Suspense fallback={null}>
|
|
<LoginForm />
|
|
</Suspense>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<SiteFooter />
|
|
<PageSchema schema={schema} />
|
|
</div>
|
|
);
|
|
}
|
|
`);
|
|
|
|
// ─── Updated register/page.tsx ───────────────────────────────────────────────
|
|
writeFileSync("app/register/page.tsx", `"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState, FormEvent } from "react";
|
|
import { PageSchema } from "../../components/page-schema";
|
|
import { SiteFooter } from "../../components/site-footer";
|
|
import { SiteHeader } from "../../components/site-header";
|
|
import { defaultFaqs } from "../../data/faq";
|
|
import { siteInfo } from "../../data/site";
|
|
import { storeAuthTokens } from "../../lib/api";
|
|
|
|
type ApiResponse<T> = {
|
|
data: T;
|
|
meta: { timestamp: string; version: "v1" };
|
|
error: null | { message: string; code?: string };
|
|
};
|
|
|
|
type AuthData = {
|
|
user: { id: string; email: string; fullName?: string };
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
message?: string;
|
|
};
|
|
|
|
export default function RegisterPage() {
|
|
const router = useRouter();
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [status, setStatus] = useState<string>("");
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const schema = [
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "WebPage",
|
|
name: "LedgerOne Create Account",
|
|
description: "Create a LedgerOne account and start with two free accounts.",
|
|
url: \`\${siteInfo.url}/register\`,
|
|
},
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "FAQPage",
|
|
mainEntity: defaultFaqs.map((item) => ({
|
|
"@type": "Question",
|
|
name: item.question,
|
|
acceptedAnswer: { "@type": "Answer", text: item.answer },
|
|
})),
|
|
},
|
|
];
|
|
|
|
const onSubmit = async (event: FormEvent) => {
|
|
event.preventDefault();
|
|
setStatus("Creating account...");
|
|
setIsError(false);
|
|
try {
|
|
const res = await fetch("/api/auth/register", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email, password }),
|
|
});
|
|
const payload = (await res.json()) as ApiResponse<AuthData>;
|
|
if (!res.ok || payload.error) {
|
|
setStatus(payload.error?.message ?? "Registration failed.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
storeAuthTokens({
|
|
accessToken: payload.data.accessToken,
|
|
refreshToken: payload.data.refreshToken,
|
|
user: payload.data.user,
|
|
});
|
|
setStatus("Account created! Please verify your email.");
|
|
router.push("/app");
|
|
} catch {
|
|
setStatus("Registration failed. Please try again.");
|
|
setIsError(true);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background font-sans text-foreground">
|
|
<SiteHeader />
|
|
<div className="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8 mt-16 relative">
|
|
<div className="absolute inset-0 mesh-gradient -z-10 opacity-30" />
|
|
<div className="sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="flex justify-center">
|
|
<div className="h-12 w-12 rounded-xl bg-primary flex items-center justify-center text-primary-foreground font-bold text-xl shadow-glow-teal">
|
|
L1
|
|
</div>
|
|
</div>
|
|
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-foreground">
|
|
Create your account
|
|
</h2>
|
|
<p className="mt-2 text-center text-sm text-muted-foreground">
|
|
Already have an account?{" "}
|
|
<Link href="/login" className="font-medium text-primary hover:text-primary/80 transition-colors">
|
|
Sign in
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="glass-panel py-8 px-4 shadow-xl sm:rounded-xl sm:px-10">
|
|
<form className="space-y-6" onSubmit={onSubmit}>
|
|
<div>
|
|
<label htmlFor="email" className="block text-sm font-medium text-foreground">
|
|
Email address
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="email" name="email" type="email" autoComplete="email" required
|
|
value={email} onChange={(e) => setEmail(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="password" className="block text-sm font-medium text-foreground">
|
|
Password
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="password" name="password" type="password" autoComplete="new-password" required
|
|
minLength={8}
|
|
value={password} onChange={(e) => setPassword(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
<p className="mt-1 text-xs text-muted-foreground">Minimum 8 characters</p>
|
|
</div>
|
|
<div>
|
|
<div className="flex items-center gap-2 mb-6">
|
|
<input
|
|
id="terms" name="terms" type="checkbox" required
|
|
className="h-4 w-4 rounded border-border bg-background/50 text-primary focus:ring-primary"
|
|
onChange={(e) => {
|
|
const btn = document.getElementById("submit-btn") as HTMLButtonElement;
|
|
if (btn) btn.disabled = !e.target.checked;
|
|
}}
|
|
/>
|
|
<label htmlFor="terms" className="text-sm text-muted-foreground">
|
|
I agree to the{" "}
|
|
<Link href="/terms" className="text-primary hover:underline">Terms of Service</Link>{" "}
|
|
and{" "}
|
|
<Link href="/privacy-policy" className="text-primary hover:underline">Privacy Policy</Link>
|
|
</label>
|
|
</div>
|
|
<button
|
|
id="submit-btn" type="submit" disabled
|
|
className="flex w-full justify-center rounded-lg border border-transparent bg-primary py-2.5 px-4 text-sm font-bold text-primary-foreground shadow-sm hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 transition-all hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0"
|
|
>
|
|
Create account
|
|
</button>
|
|
</div>
|
|
</form>
|
|
{status && (
|
|
<div className={\`mt-4 rounded-lg p-4 \${isError ? "bg-red-500/10 border border-red-500/20" : "bg-accent/10 border border-accent/20"}\`}>
|
|
<p className="text-sm font-medium text-center">{status}</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<SiteFooter />
|
|
<PageSchema schema={schema} />
|
|
</div>
|
|
);
|
|
}
|
|
`);
|
|
|
|
// ─── New forgot-password/page.tsx ────────────────────────────────────────────
|
|
mkdirSync("app/forgot-password", { recursive: true });
|
|
writeFileSync("app/forgot-password/page.tsx", `"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useState } from "react";
|
|
import { SiteFooter } from "../../components/site-footer";
|
|
import { SiteHeader } from "../../components/site-header";
|
|
|
|
type ApiResponse<T> = {
|
|
data: T;
|
|
meta: { timestamp: string; version: "v1" };
|
|
error: null | { message: string; code?: string };
|
|
};
|
|
|
|
export default function ForgotPasswordPage() {
|
|
const [email, setEmail] = useState("");
|
|
const [status, setStatus] = useState("");
|
|
const [sent, setSent] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const onSubmit = async (event: React.FormEvent) => {
|
|
event.preventDefault();
|
|
setStatus("Sending reset link...");
|
|
setIsError(false);
|
|
try {
|
|
const res = await fetch("/api/auth/forgot-password", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email }),
|
|
});
|
|
const payload = (await res.json()) as ApiResponse<{ message: string }>;
|
|
if (!res.ok && payload.error) {
|
|
setStatus(payload.error.message ?? "Something went wrong.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
setSent(true);
|
|
setStatus(payload.data?.message ?? "If that email exists, a reset link has been sent.");
|
|
} catch {
|
|
setStatus("Something went wrong. Please try again.");
|
|
setIsError(true);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background font-sans text-foreground">
|
|
<SiteHeader />
|
|
<div className="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8 mt-16 relative">
|
|
<div className="absolute inset-0 mesh-gradient -z-10 opacity-30" />
|
|
<div className="sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="flex justify-center">
|
|
<div className="h-12 w-12 rounded-xl bg-primary flex items-center justify-center text-primary-foreground font-bold text-xl shadow-glow-teal">
|
|
L1
|
|
</div>
|
|
</div>
|
|
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-foreground">
|
|
Reset your password
|
|
</h2>
|
|
<p className="mt-2 text-center text-sm text-muted-foreground">
|
|
<Link href="/login" className="font-medium text-primary hover:text-primary/80 transition-colors">
|
|
Back to sign in
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="glass-panel py-8 px-4 shadow-xl sm:rounded-xl sm:px-10">
|
|
{sent ? (
|
|
<div className="text-center space-y-4">
|
|
<div className="mx-auto h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center">
|
|
<svg className="h-6 w-6 text-primary" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
|
</svg>
|
|
</div>
|
|
<p className="text-sm text-foreground font-medium">{status}</p>
|
|
<p className="text-xs text-muted-foreground">Check your email inbox and spam folder.</p>
|
|
<Link href="/login" className="inline-flex justify-center rounded-lg bg-primary py-2 px-4 text-sm font-bold text-primary-foreground hover:bg-primary/90 transition-all">
|
|
Back to sign in
|
|
</Link>
|
|
</div>
|
|
) : (
|
|
<form className="space-y-6" onSubmit={onSubmit}>
|
|
<div>
|
|
<label htmlFor="email" className="block text-sm font-medium text-foreground">
|
|
Email address
|
|
</label>
|
|
<p className="mt-1 text-xs text-muted-foreground">
|
|
We'll send a reset link to this address if it has an account.
|
|
</p>
|
|
<div className="mt-2">
|
|
<input
|
|
id="email" name="email" type="email" autoComplete="email" required
|
|
value={email} onChange={(e) => setEmail(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<button
|
|
type="submit"
|
|
className="flex w-full justify-center rounded-lg border border-transparent bg-primary py-2.5 px-4 text-sm font-bold text-primary-foreground shadow-sm hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 transition-all hover:-translate-y-0.5"
|
|
>
|
|
Send reset link
|
|
</button>
|
|
{isError && status && (
|
|
<div className="rounded-lg bg-red-500/10 border border-red-500/20 p-4">
|
|
<p className="text-sm text-center">{status}</p>
|
|
</div>
|
|
)}
|
|
</form>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<SiteFooter />
|
|
</div>
|
|
);
|
|
}
|
|
`);
|
|
|
|
// ─── New verify-email/page.tsx ───────────────────────────────────────────────
|
|
mkdirSync("app/verify-email", { recursive: true });
|
|
writeFileSync("app/verify-email/page.tsx", `"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useSearchParams } from "next/navigation";
|
|
import { useEffect, useState, Suspense } from "react";
|
|
import { SiteFooter } from "../../components/site-footer";
|
|
import { SiteHeader } from "../../components/site-header";
|
|
|
|
type ApiResponse<T> = {
|
|
data: T;
|
|
meta: { timestamp: string; version: "v1" };
|
|
error: null | { message: string; code?: string };
|
|
};
|
|
|
|
function VerifyEmailContent() {
|
|
const searchParams = useSearchParams();
|
|
const token = searchParams.get("token");
|
|
const [status, setStatus] = useState<"loading" | "success" | "error">("loading");
|
|
const [message, setMessage] = useState("");
|
|
|
|
useEffect(() => {
|
|
if (!token) {
|
|
setStatus("error");
|
|
setMessage("No verification token provided.");
|
|
return;
|
|
}
|
|
fetch(\`/api/auth/verify-email?token=\${encodeURIComponent(token)}\`)
|
|
.then((res) => res.json() as Promise<ApiResponse<{ message: string }>>)
|
|
.then((payload) => {
|
|
if (payload.error) {
|
|
setStatus("error");
|
|
setMessage(payload.error.message ?? "Verification failed.");
|
|
} else {
|
|
setStatus("success");
|
|
setMessage(payload.data?.message ?? "Email verified successfully.");
|
|
}
|
|
})
|
|
.catch(() => {
|
|
setStatus("error");
|
|
setMessage("Something went wrong. Please try again.");
|
|
});
|
|
}, [token]);
|
|
|
|
return (
|
|
<div className="text-center space-y-4">
|
|
{status === "loading" && (
|
|
<>
|
|
<div className="mx-auto h-12 w-12 rounded-full border-2 border-primary border-t-transparent animate-spin" />
|
|
<p className="text-sm text-muted-foreground">Verifying your email...</p>
|
|
</>
|
|
)}
|
|
{status === "success" && (
|
|
<>
|
|
<div className="mx-auto h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center">
|
|
<svg className="h-6 w-6 text-primary" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
</svg>
|
|
</div>
|
|
<p className="text-lg font-semibold text-foreground">Email Verified!</p>
|
|
<p className="text-sm text-muted-foreground">{message}</p>
|
|
<Link
|
|
href="/login"
|
|
className="inline-flex justify-center rounded-lg bg-primary py-2 px-6 text-sm font-bold text-primary-foreground hover:bg-primary/90 transition-all"
|
|
>
|
|
Sign in
|
|
</Link>
|
|
</>
|
|
)}
|
|
{status === "error" && (
|
|
<>
|
|
<div className="mx-auto h-12 w-12 rounded-full bg-red-500/10 flex items-center justify-center">
|
|
<svg className="h-6 w-6 text-red-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
</svg>
|
|
</div>
|
|
<p className="text-lg font-semibold text-foreground">Verification Failed</p>
|
|
<p className="text-sm text-muted-foreground">{message}</p>
|
|
<p className="text-xs text-muted-foreground">The link may have expired. Please register again or contact support.</p>
|
|
<Link
|
|
href="/login"
|
|
className="inline-flex justify-center rounded-lg bg-primary py-2 px-6 text-sm font-bold text-primary-foreground hover:bg-primary/90 transition-all"
|
|
>
|
|
Back to sign in
|
|
</Link>
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function VerifyEmailPage() {
|
|
return (
|
|
<div className="min-h-screen bg-background font-sans text-foreground">
|
|
<SiteHeader />
|
|
<div className="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8 mt-16 relative">
|
|
<div className="absolute inset-0 mesh-gradient -z-10 opacity-30" />
|
|
<div className="sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="flex justify-center">
|
|
<div className="h-12 w-12 rounded-xl bg-primary flex items-center justify-center text-primary-foreground font-bold text-xl shadow-glow-teal">
|
|
L1
|
|
</div>
|
|
</div>
|
|
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-foreground">
|
|
Email Verification
|
|
</h2>
|
|
</div>
|
|
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="glass-panel py-8 px-4 shadow-xl sm:rounded-xl sm:px-10">
|
|
<Suspense fallback={<div className="text-center text-sm text-muted-foreground">Loading...</div>}>
|
|
<VerifyEmailContent />
|
|
</Suspense>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<SiteFooter />
|
|
</div>
|
|
);
|
|
}
|
|
`);
|
|
|
|
// ─── New reset-password/page.tsx ─────────────────────────────────────────────
|
|
mkdirSync("app/reset-password", { recursive: true });
|
|
writeFileSync("app/reset-password/page.tsx", `"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
import { Suspense, useState } from "react";
|
|
import { SiteFooter } from "../../components/site-footer";
|
|
import { SiteHeader } from "../../components/site-header";
|
|
|
|
type ApiResponse<T> = {
|
|
data: T;
|
|
meta: { timestamp: string; version: "v1" };
|
|
error: null | { message: string; code?: string };
|
|
};
|
|
|
|
function ResetPasswordForm() {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
const token = searchParams.get("token") ?? "";
|
|
|
|
const [password, setPassword] = useState("");
|
|
const [confirm, setConfirm] = useState("");
|
|
const [status, setStatus] = useState("");
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const onSubmit = async (event: React.FormEvent) => {
|
|
event.preventDefault();
|
|
if (password !== confirm) {
|
|
setStatus("Passwords do not match.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
if (password.length < 8) {
|
|
setStatus("Password must be at least 8 characters.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
if (!token) {
|
|
setStatus("Missing reset token. Please use the link from your email.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
setStatus("Resetting password...");
|
|
setIsError(false);
|
|
try {
|
|
const res = await fetch("/api/auth/reset-password", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ token, password }),
|
|
});
|
|
const payload = (await res.json()) as ApiResponse<{ message: string }>;
|
|
if (!res.ok || payload.error) {
|
|
setStatus(payload.error?.message ?? "Reset failed. The link may have expired.");
|
|
setIsError(true);
|
|
return;
|
|
}
|
|
setStatus("Password reset successfully! Redirecting to sign in...");
|
|
setTimeout(() => router.push("/login"), 2000);
|
|
} catch {
|
|
setStatus("Something went wrong. Please try again.");
|
|
setIsError(true);
|
|
}
|
|
};
|
|
|
|
if (!token) {
|
|
return (
|
|
<div className="text-center space-y-4">
|
|
<p className="text-sm text-muted-foreground">Invalid reset link. Please request a new one.</p>
|
|
<Link href="/forgot-password" className="text-primary hover:underline text-sm">Request password reset</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<form className="space-y-6" onSubmit={onSubmit}>
|
|
<div>
|
|
<label htmlFor="password" className="block text-sm font-medium text-foreground">
|
|
New Password
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="password" name="password" type="password" autoComplete="new-password" required minLength={8}
|
|
value={password} onChange={(e) => setPassword(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
<p className="mt-1 text-xs text-muted-foreground">Minimum 8 characters</p>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="confirm" className="block text-sm font-medium text-foreground">
|
|
Confirm Password
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
id="confirm" name="confirm" type="password" autoComplete="new-password" required
|
|
value={confirm} onChange={(e) => setConfirm(e.target.value)}
|
|
className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-primary sm:text-sm transition-all"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<button
|
|
type="submit"
|
|
className="flex w-full justify-center rounded-lg border border-transparent bg-primary py-2.5 px-4 text-sm font-bold text-primary-foreground shadow-sm hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 transition-all hover:-translate-y-0.5"
|
|
>
|
|
Reset Password
|
|
</button>
|
|
{status && (
|
|
<div className={\`rounded-lg p-4 \${isError ? "bg-red-500/10 border border-red-500/20" : "bg-accent/10 border border-accent/20"}\`}>
|
|
<p className="text-sm text-center">{status}</p>
|
|
</div>
|
|
)}
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export default function ResetPasswordPage() {
|
|
return (
|
|
<div className="min-h-screen bg-background font-sans text-foreground">
|
|
<SiteHeader />
|
|
<div className="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8 mt-16 relative">
|
|
<div className="absolute inset-0 mesh-gradient -z-10 opacity-30" />
|
|
<div className="sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="flex justify-center">
|
|
<div className="h-12 w-12 rounded-xl bg-primary flex items-center justify-center text-primary-foreground font-bold text-xl shadow-glow-teal">
|
|
L1
|
|
</div>
|
|
</div>
|
|
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-foreground">
|
|
Set new password
|
|
</h2>
|
|
<p className="mt-2 text-center text-sm text-muted-foreground">
|
|
<Link href="/login" className="font-medium text-primary hover:text-primary/80 transition-colors">
|
|
Back to sign in
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
|
<div className="glass-panel py-8 px-4 shadow-xl sm:rounded-xl sm:px-10">
|
|
<Suspense fallback={<div className="text-center text-sm text-muted-foreground">Loading...</div>}>
|
|
<ResetPasswordForm />
|
|
</Suspense>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<SiteFooter />
|
|
</div>
|
|
);
|
|
}
|
|
`);
|
|
|
|
console.log("✅ login, register, forgot-password, verify-email, reset-password pages written");
|