diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2025-08-18 23:50:03 +0200 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2025-08-18 23:50:03 +0200 |
commit | 5e3a28bafde748367a0566d739e1c098af2c0a0f (patch) | |
tree | ee4cbc52b044bd2f42391825a01d8386741f01fa /src/index.tsx | |
parent | 3262d631fd1be55a5c85ede08d92a35c5fb7d2c4 (diff) | |
download | uneven-5e3a28bafde748367a0566d739e1c098af2c0a0f.tar.gz |
Group <-> User membershipsmaster
Diffstat (limited to 'src/index.tsx')
-rw-r--r-- | src/index.tsx | 24 |
1 files changed, 14 insertions, 10 deletions
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 <ul>{ - result.map(group => <li>{group.name}</li>) - }</ul>; -} + return c.html(<ul>{ + user.groups.map(group => <li>{group.group.name}</li>) + }</ul>); +}); app.get("/", c => c.html( <html lang="en"> @@ -31,8 +35,8 @@ app.get("/", c => c.html( </head> <body> <LoginForm /> - <Groups /> <button hx-get="/button" hx-swap="outerHTML">click me!</button> + <div hx-on-load="/groups" hx-swap="outerHTML" /> </body> </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}</button> + >disco button! {session?.user.name}</button> ); }); |