feat: add login page and auth API route

This commit is contained in:
Manohar Gupta 2026-05-10 04:09:19 +05:30
parent 7098339200
commit 330367dcc8
4 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,4 @@
import { handlers } from "@/auth";
export const GET = handlers.GET;
export const POST = handlers.POST;

43
src/app/login/page.tsx Normal file
View file

@ -0,0 +1,43 @@
"use client";
import { signIn } from "next-auth/react";
import { useState } from "react";
export default function LoginPage() {
const [email, setEmail] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
await signIn("email", { email });
setLoading(false);
};
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-rose-50 to-amber-50">
<div className="w-full max-w-md p-8">
<h1 className="text-3xl font-bold text-center mb-2">Tia</h1>
<p className="text-center text-gray-600 mb-8">Your baby tracking companion</p>
<form onSubmit={handleSubmit} className="space-y-4">
<input
type="email"
placeholder="Your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full p-4 border rounded-2xl bg-white shadow-sm focus:ring-2 focus:ring-rose-200 outline-none"
required
/>
<button
type="submit"
disabled={loading}
className="w-full p-4 bg-rose-400 text-white rounded-2xl font-medium shadow-md hover:bg-rose-500 transition disabled:opacity-50"
>
{loading ? "Sending..." : "Send Magic Link"}
</button>
</form>
</div>
</div>
);
}

21
src/auth.ts Normal file
View file

@ -0,0 +1,21 @@
import NextAuth from "next-auth";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "@/db";
import { accounts, sessions, users, verificationTokens } from "@/db/schema/auth";
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: DrizzleAdapter(db, {
accountsTable: accounts,
sessionsTable: sessions,
usersTable: users,
verificationTokensTable: verificationTokens,
}),
providers: [],
pages: {
signIn: "/login",
},
session: {
strategy: "database",
maxAge: 30 * 24 * 60 * 60,
},
});

11
src/middleware.ts Normal file
View file

@ -0,0 +1,11 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
// For now, just log and continue - auth setup comes later
return NextResponse.next();
}
export const config = {
matcher: ["/((?!login|verify|api/auth|_next|static|favicon.ico).*)"],
};