This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
+18
-18
@@ -13,24 +13,24 @@ import { sessionUserId } from "@/lib/auth/session-user";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const session = await auth();
|
||||
const id = sessionUserId(session?.user?.id);
|
||||
if (!id) {
|
||||
return apiError("Unauthorized", 401);
|
||||
}
|
||||
const session = await auth();
|
||||
const id = sessionUserId(session?.user?.id);
|
||||
if (!id) {
|
||||
return apiError("Unauthorized", 401);
|
||||
}
|
||||
|
||||
const body = (await req.json().catch(() => ({}))) as { name?: unknown };
|
||||
const rawName = typeof body.name === "string" ? body.name.trim() : "";
|
||||
const name = rawName ? rawName.slice(0, 100) : "api";
|
||||
const body = (await req.json().catch(() => ({}))) as { name?: unknown };
|
||||
const rawName = typeof body.name === "string" ? body.name.trim() : "";
|
||||
const name = rawName ? rawName.slice(0, 100) : "api";
|
||||
|
||||
try {
|
||||
const token = await issueToken(id, name);
|
||||
if (!token) {
|
||||
return apiError("Could not issue token", 500);
|
||||
}
|
||||
// Plaintext token — shown only once, never recoverable afterwards.
|
||||
return apiJson({ token });
|
||||
} catch {
|
||||
return apiError("Could not issue token", 500);
|
||||
}
|
||||
try {
|
||||
const token = await issueToken(id, name);
|
||||
if (!token) {
|
||||
return apiError("Could not issue token", 500);
|
||||
}
|
||||
// Plaintext token — shown only once, never recoverable afterwards.
|
||||
return apiJson({ token });
|
||||
} catch {
|
||||
return apiError("Could not issue token", 500);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user