From 5e3a28bafde748367a0566d739e1c098af2c0a0f Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Mon, 18 Aug 2025 23:50:03 +0200 Subject: Group <-> User memberships --- src/index.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/index.tsx') diff --git a/src/index.tsx b/src/index.tsx index 5975284..ea79902 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,22 +2,26 @@ import { serve } from "@hono/node-server"; import { Hono } from "hono"; import { createClient } from "@libsql/client"; import { drizzle } from "drizzle-orm/libsql"; -import { groupTable } from "./db/schema.js"; +import * as schema from "./db/schema.js"; import authRouter, { getSession, LoginForm } from "./auth.js"; +import { eq } from "drizzle-orm"; export const RP_ID = "localhost"; // "uneven.0m.nu"; export const ORIGIN = `http://${RP_ID}`; let app = new Hono(); -export let db = drizzle(createClient({ url: "file:data.db" })); +export let db = drizzle(createClient({ url: "file:data.db" }), { schema }); -async function Groups() { - let result = await db.select().from(groupTable).all(); +app.get("/groups", async c => { + let session = await getSession(c); + if (!session) return c.html("Must be logged in"); + let user = await db.query.userTable.findFirst({ where: user => eq(user.id, session.user.id), with: { groups: { with: { group: true } } } }); + if (!user) return c.html("Huh?"); - return ; -} + return c.html(); +}); app.get("/", c => c.html( @@ -31,8 +35,8 @@ app.get("/", c => c.html( - +
)); @@ -45,7 +49,7 @@ app.get("/button", async c => { hx-get="/button" hx-swap="outerHTML" style={{ backgroundColor: colors[Math.floor(Math.random() * colors.length)] }} - >disco button! {session.user.name} + >disco button! {session?.user.name} ); }); -- cgit v1.2.3