import { db } from "$lib/db/db.server"; import { sessionsTable, usersTable } from "$lib/db/schema"; import { eq } from "drizzle-orm"; import type { PgUUID } from "drizzle-orm/pg-core"; export async function createSession(user_id: string) { const session = await db.insert(sessionsTable).values({ user_id: user_id }).returning({ id: sessionsTable.id }); return session[0].id; } export async function validateSession(session_id: string) { try { const session = await db.select().from(sessionsTable).where(eq(sessionsTable.id, session_id)).leftJoin(usersTable, eq(usersTable.id, sessionsTable.user_id)); return session[0].users; } catch (e) { return false; } }