Something went wrong. Try again.
spool is a community-first, lightweight discussion forum, issue tracker, and announcement hub for your project.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637import crypto from "node:crypto";import { Hono } from "hono";import { db } from "../db/index.js";import { users } from "../db/schema.js";import { createSession, type AuthEnv } from "./session.js";
const APP_URL = process.env.APP_URL ?? "http://localhost:5173";
// Deterministic *negative* id so impersonated identities can never collide// with real GitHub account ids. Also used by the seed script.export function devGithubId(username: string): number { const hex = crypto.createHash("sha1").update(username).digest("hex").slice(0, 8); return -Number.parseInt(hex, 16);}
// Dev-only identity impersonation: GET /auth/dev/ada signs you in as "ada",// creating the user if needed. Hard-disabled in production.const dev = new Hono<AuthEnv>();
dev.get("/dev/:username", async (c) => { if (process.env.NODE_ENV === "production") return c.notFound();
const username = c.req.param("username").toLowerCase().replace(/[^a-z0-9-]/g, ""); if (!username) return c.json({ error: "Invalid username" }, 400);
const [user] = await db .insert(users) .values({ githubId: devGithubId(username), username, avatarUrl: null }) .onConflictDoUpdate({ target: users.githubId, set: { username } }) .returning();
await createSession(c, user.id); return c.redirect(APP_URL);});
export default dev;