api/me routing
This commit is contained in:
parent
b54120d88e
commit
3dc4f011d7
1 changed files with 22 additions and 0 deletions
22
app/api/me/route.ts
Normal file
22
app/api/me/route.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// app/api/me/route.ts
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { requireBearer } from "@/app/api/_lib/auth";
|
||||||
|
import { dxGET } from "@/lib/directus";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export async function GET(req: Request) {
|
||||||
|
try {
|
||||||
|
const bearer = requireBearer(req);
|
||||||
|
// Return only safe fields the UI needs
|
||||||
|
const res = await dxGET<any>(
|
||||||
|
"/users/me?fields=id,username,display_name,first_name,last_name,email",
|
||||||
|
bearer
|
||||||
|
);
|
||||||
|
const me = res?.data ?? res;
|
||||||
|
return NextResponse.json(me);
|
||||||
|
} catch (e: any) {
|
||||||
|
const status = e?.status ?? 500;
|
||||||
|
return NextResponse.json({ error: e?.message || "Failed to load user" }, { status });
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue