Fix login page to use real signin API, fix setup route db.execute()
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
ab9aa1052e
commit
8ca54fec30
2 changed files with 45 additions and 16 deletions
|
|
@ -1,17 +1,16 @@
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import { sql } from "drizzle-orm/postgres-js";
|
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
// Create enums
|
// Create enums
|
||||||
await db.execute(sql`CREATE TYPE IF NOT EXISTS child_sex AS ENUM('male', 'female', 'other')`);
|
await db.execute(`CREATE TYPE IF NOT EXISTS child_sex AS ENUM('male', 'female', 'other')`);
|
||||||
await db.execute(sql`CREATE TYPE IF NOT EXISTS child_stage AS ENUM('newborn', 'infant', 'solids_start', 'toddler_early', 'toddler_late', 'preschool')`);
|
await db.execute(`CREATE TYPE IF NOT EXISTS child_stage AS ENUM('newborn', 'infant', 'solids_start', 'toddler_early', 'toddler_late', 'preschool')`);
|
||||||
await db.execute(sql`CREATE TYPE IF NOT EXISTS member_role AS ENUM('admin', 'caregiver', 'viewer')`);
|
await db.execute(`CREATE TYPE IF NOT EXISTS member_role AS ENUM('admin', 'caregiver', 'viewer')`);
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Types created" });
|
return NextResponse.json({ success: true, message: "Types created" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ error: String(error) }, { status: 500 });
|
return NextResponse.json({ error: String(error) }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,32 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const handleLogin = () => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
// For demo: just go to home
|
e.preventDefault();
|
||||||
// In real app, this connects to auth
|
setLoading(true);
|
||||||
router.push("/");
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/auth/signin", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ email }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
router.push("/");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -16,13 +34,25 @@ export default function LoginPage() {
|
||||||
<div className="w-full max-w-md p-8 text-center">
|
<div className="w-full max-w-md p-8 text-center">
|
||||||
<h1 className="text-4xl font-bold mb-2">Tia</h1>
|
<h1 className="text-4xl font-bold mb-2">Tia</h1>
|
||||||
<p className="text-gray-600 mb-8">Your baby tracking companion</p>
|
<p className="text-gray-600 mb-8">Your baby tracking companion</p>
|
||||||
<button
|
|
||||||
onClick={handleLogin}
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
className="w-full p-4 bg-rose-400 text-white rounded-2xl font-medium shadow-md hover:bg-rose-500 transition"
|
<input
|
||||||
>
|
type="email"
|
||||||
Enter App (Demo)
|
placeholder="Enter your email"
|
||||||
</button>
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
className="w-full p-4 border rounded-2xl bg-white shadow-sm"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={loading}
|
||||||
|
className="w-full p-4 bg-rose-400 text-white rounded-2xl font-medium"
|
||||||
|
>
|
||||||
|
{loading ? "Signing in..." : "Sign In"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue