nova-store/app/api/me/route.js

12 lines
472 B
JavaScript

import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import db from "../../lib/db";
import { readSession } from "../../lib/auth";
export async function GET() {
const store = await cookies();
const id = readSession(store.get("session")?.value);
if (!id) return NextResponse.json({ user: null });
const user = db.prepare("SELECT id, name, email FROM users WHERE id = ?").get(id);
return NextResponse.json({ user: user || null });
}