DB-backed workspace + LangGraph agent
This commit is contained in:
35
Frontend/server/api/auth/login.post.ts
Normal file
35
Frontend/server/api/auth/login.post.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { readBody } from "h3";
|
||||
import { prisma } from "../../utils/prisma";
|
||||
import { setSession } from "../../utils/auth";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{ email?: string; name?: string; teamName?: string }>(event);
|
||||
const email = (body?.email ?? "").trim().toLowerCase();
|
||||
const name = (body?.name ?? "").trim();
|
||||
const teamName = (body?.teamName ?? "").trim() || "My Team";
|
||||
|
||||
if (!email || !email.includes("@")) {
|
||||
throw createError({ statusCode: 400, statusMessage: "valid email is required" });
|
||||
}
|
||||
if (!name) {
|
||||
throw createError({ statusCode: 400, statusMessage: "name is required" });
|
||||
}
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email },
|
||||
update: { name },
|
||||
create: { email, name },
|
||||
});
|
||||
|
||||
// For MVP: 1 user -> 1 team (created if missing)
|
||||
const team = await prisma.team.create({ data: { name: teamName } });
|
||||
await prisma.teamMember.create({ data: { teamId: team.id, userId: user.id, role: "OWNER" } });
|
||||
|
||||
const conversation = await prisma.chatConversation.create({
|
||||
data: { teamId: team.id, createdByUserId: user.id, title: "Pilot" },
|
||||
});
|
||||
|
||||
setSession(event, { teamId: team.id, userId: user.id, conversationId: conversation.id });
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user