cg / hackerproducts

64 files · 5,803 lines · 161.0 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / app / api / auth / dev / route.ts

src/app/api/auth/dev/route.ts · 29 lines · 1011 B← back to folder
1import { NextResponse } from "next/server";
2import { createSession, getAuthProviders, getSiteUrl, upsertOAuthUser } from "@/lib/auth";
3import { sanitizeUsername } from "@/lib/validation";
4
5export async function POST(request: Request) {
6 if (!getAuthProviders().dev) {
7 return NextResponse.json({ error: "Dev login is disabled." }, { status: 403 });
8 }
9
10 const body = (await request.json().catch(() => ({}))) as {
11 username?: string;
12 next?: string;
13 };
14
15 const preferred = sanitizeUsername(body.username || "arden") || "arden";
16 const user = await upsertOAuthUser({
17 provider: "dev",
18 providerAccountId: `dev_${preferred}`,
19 email: `${preferred}@example.com`,
20 name: preferred,
21 preferredUsername: preferred,
22 avatarUrl: null,
23 });
24
25 await createSession(user.id);
26 const next = body.next && body.next.startsWith("/") && !body.next.startsWith("//") ? body.next : "/";
27 return NextResponse.json({ ok: true, user: { username: user.username }, next, siteUrl: getSiteUrl() });
28}
29
cg / hackerproducts — hacker products