From 3262d631fd1be55a5c85ede08d92a35c5fb7d2c4 Mon Sep 17 00:00:00 2001
From: Mathias Magnusson <mathias@magnusson.space>
Date: Mon, 18 Aug 2025 21:43:11 +0200
Subject: Get current user session

---
 src/index.tsx | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index e029577..5975284 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -3,7 +3,7 @@ import { Hono } from "hono";
 import { createClient } from "@libsql/client";
 import { drizzle } from "drizzle-orm/libsql";
 import { groupTable } from "./db/schema.js";
-import authRouter, { LoginForm } from "./auth.js";
+import authRouter, { getSession, LoginForm } from "./auth.js";
 
 export const RP_ID = "localhost"; // "uneven.0m.nu";
 export const ORIGIN = `http://${RP_ID}`;
@@ -38,13 +38,16 @@ app.get("/", c => c.html(
 ));
 
 let colors = ["red", "green", "blue"];
-app.get("/button", c => c.html(
-  <button
-    hx-get="/button"
-    hx-swap="outerHTML"
-    style={{ backgroundColor: colors[Math.floor(Math.random() * colors.length)] }}
-  >disco button!</button>
-));
+app.get("/button", async c => {
+  let session = await getSession(c);
+  return c.html(
+    <button
+      hx-get="/button"
+      hx-swap="outerHTML"
+      style={{ backgroundColor: colors[Math.floor(Math.random() * colors.length)] }}
+    >disco button! {session.user.name}</button>
+  );
+});
 
 app.route("/auth", authRouter);
 
-- 
cgit v1.2.3

