From 330367dcc8b3d26d498b534b0de501b214d7d2bd Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 10 May 2026 04:09:19 +0530 Subject: [PATCH] feat: add login page and auth API route --- src/app/api/auth/[...nextauth]/route.ts | 4 +++ src/app/login/page.tsx | 43 +++++++++++++++++++++++++ src/auth.ts | 21 ++++++++++++ src/middleware.ts | 11 +++++++ 4 files changed, 79 insertions(+) create mode 100644 src/app/api/auth/[...nextauth]/route.ts create mode 100644 src/app/login/page.tsx create mode 100644 src/auth.ts create mode 100644 src/middleware.ts diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..154979f --- /dev/null +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,4 @@ +import { handlers } from "@/auth"; + +export const GET = handlers.GET; +export const POST = handlers.POST; \ No newline at end of file diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx new file mode 100644 index 0000000..06bd0a6 --- /dev/null +++ b/src/app/login/page.tsx @@ -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 ( +
+
+

Tia

+

Your baby tracking companion

+ +
+ 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 + /> + +
+
+
+ ); +} \ No newline at end of file diff --git a/src/auth.ts b/src/auth.ts new file mode 100644 index 0000000..c6e53bd --- /dev/null +++ b/src/auth.ts @@ -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, + }, +}); \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..96de7bb --- /dev/null +++ b/src/middleware.ts @@ -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).*)"], +}; \ No newline at end of file