nextjs-rewrite (#5)

Reviewed-on: #5
Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #5.
This commit is contained in:
2026-03-30 02:30:13 +00:00
committed by david
parent 1a9b3496e1
commit 123df671f5
160 changed files with 19293 additions and 1180 deletions
+119
View File
@@ -0,0 +1,119 @@
"use client"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { useState } from "react"
import { authClient } from "@/lib/auth-client"
export default function LoginPage() {
const router = useRouter()
const [error, setError] = useState("")
const [loading, setLoading] = useState(false)
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault()
console.log("Login form submitted via JavaScript handler")
setLoading(true)
setError("")
const formData = new FormData(e.currentTarget)
const email = formData.get("email") as string
const password = formData.get("password") as string
try {
const result = await authClient.signIn.email({
email,
password,
})
if (result.error) {
setError(result.error.message || "Failed to sign in")
} else {
// Navigate to admin page - Better Auth will handle session update
router.push("/admin")
}
} catch (err) {
setError("An unexpected error occurred")
} finally {
setLoading(false)
}
}
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
<div className="max-w-md w-full space-y-8">
<div>
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
Sign in to your account
</h2>
</div>
<form className="mt-8 space-y-6" method="POST" onSubmit={handleSubmit}>
{error && (
<div className="rounded-md bg-red-50 p-4">
<div className="text-sm text-red-700">{error}</div>
</div>
)}
<div className="rounded-md shadow-sm -space-y-px">
<div>
<label htmlFor="email" className="sr-only">
Email address
</label>
<input
id="email"
name="email"
type="email"
autoComplete="email"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-green-500 focus:border-green-500 focus:z-10 sm:text-sm"
placeholder="Email address"
/>
</div>
<div>
<label htmlFor="password" className="sr-only">
Password
</label>
<input
id="password"
name="password"
type="password"
autoComplete="current-password"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-green-500 focus:border-green-500 focus:z-10 sm:text-sm"
placeholder="Password"
/>
</div>
</div>
<div>
<button
type="submit"
disabled={loading}
className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed"
>
{loading ? "Signing in..." : "Sign in"}
</button>
</div>
<div className="flex items-center justify-between">
<div className="text-sm">
<Link
href="/auth/register"
className="font-medium text-green-600 hover:text-green-500"
>
Create account
</Link>
</div>
<div className="text-sm">
<Link
href="/auth/password-reset"
className="font-medium text-green-600 hover:text-green-500"
>
Forgot password?
</Link>
</div>
</div>
</form>
</div>
</div>
)
}
+138
View File
@@ -0,0 +1,138 @@
"use client"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { useState } from "react"
import { authClient } from "@/lib/auth-client"
import { useSession } from "@/components/SessionProvider"
export default function RegisterPage() {
const router = useRouter()
const { refreshSession } = useSession()
const [error, setError] = useState("")
const [loading, setLoading] = useState(false)
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault()
setLoading(true)
setError("")
const formData = new FormData(e.currentTarget)
const name = formData.get("name") as string
const email = formData.get("email") as string
const password = formData.get("password") as string
try {
console.log("Attempting signup...");
const result = await authClient.signUp.email({
email,
password,
name,
})
console.log("Signup result:", result);
if (result.error) {
console.error("Signup error:", result.error);
setError(result.error.message || "Failed to create account")
} else {
console.log("Signup successful, redirecting...");
console.log("Result data:", result.data);
// Refresh the session after successful registration
try {
await refreshSession()
console.log("Session refreshed successfully");
} catch (err) {
console.error("Failed to refresh session:", err);
}
console.log("About to redirect to /admin");
router.push("/admin")
router.refresh()
console.log("Redirect initiated");
}
} catch (err) {
console.error("Signup exception:", err);
setError("An unexpected error occurred")
} finally {
setLoading(false)
}
}
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
<div className="max-w-md w-full space-y-8">
<div>
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
Create your account
</h2>
</div>
<form className="mt-8 space-y-6" method="POST" onSubmit={handleSubmit}>
{error && (
<div className="rounded-md bg-red-50 p-4">
<div className="text-sm text-red-700">{error}</div>
</div>
)}
<div className="rounded-md shadow-sm -space-y-px">
<div>
<label htmlFor="name" className="sr-only">
Full Name
</label>
<input
id="name"
name="name"
type="text"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-green-500 focus:border-green-500 focus:z-10 sm:text-sm"
placeholder="Full Name"
/>
</div>
<div>
<label htmlFor="email" className="sr-only">
Email address
</label>
<input
id="email"
name="email"
type="email"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-green-500 focus:border-green-500 focus:z-10 sm:text-sm"
placeholder="Email address"
/>
</div>
<div>
<label htmlFor="password" className="sr-only">
Password
</label>
<input
id="password"
name="password"
type="password"
required
className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-green-500 focus:border-green-500 focus:z-10 sm:text-sm"
placeholder="Password"
/>
</div>
</div>
<div>
<button
type="submit"
disabled={loading}
className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed"
>
{loading ? "Creating..." : "Create Account"}
</button>
</div>
<div className="text-center text-sm">
<Link
href="/auth/login"
className="font-medium text-green-600 hover:text-green-500"
>
Already have an account? Sign in
</Link>
</div>
</form>
</div>
</div>
)
}
+18
View File
@@ -0,0 +1,18 @@
"use client"
export default function VerifyRequestPage() {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
<div className="max-w-md w-full space-y-8">
<div>
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
Check your email
</h2>
<p className="mt-2 text-center text-sm text-gray-600">
A sign in link has been sent to your email address.
</p>
</div>
</div>
</div>
)
}