feat: add signin API and setup route
This commit is contained in:
parent
affd70b9a7
commit
b4dc29fa3d
1 changed files with 33 additions and 0 deletions
33
src/app/api/auth/signin/route.ts
Normal file
33
src/app/api/auth/signin/route.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { db } from "@/db";
|
||||
import { users } from "@/db/schema/auth";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const { email } = await request.json();
|
||||
|
||||
if (!email) {
|
||||
return NextResponse.json({ error: "Email required" }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
// Find or create user
|
||||
let user = await db.query.users.findFirst({
|
||||
where: eq(users.email, email),
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
const [newUser] = await db
|
||||
.insert(users)
|
||||
.values({ email })
|
||||
.returning();
|
||||
user = newUser;
|
||||
}
|
||||
|
||||
// For demo, just return success - in real app, send magic link via email
|
||||
return NextResponse.json({ success: true, userId: user.id });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ error: String(error) }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue