Add dedicated users/me route using payload.auth

This commit is contained in:
Enguerrand Ozano
2026-03-01 10:58:14 +01:00
parent 142d0167a8
commit ac4a88d08b

View File

@@ -0,0 +1,25 @@
import { NextRequest, NextResponse } from 'next/server';
import payload from 'payload';
import config from '@/payload.config';
export async function GET(req: NextRequest) {
await payload.init({ config });
try {
const { user } = await payload.auth({
headers: req.headers,
});
if (!user) {
return NextResponse.json({ user: null, message: 'Account' });
}
return NextResponse.json({ user, message: 'Account' });
} catch (err) {
console.error(err);
return NextResponse.json(
{ user: null, message: 'Error checking account' },
{ status: 500 },
);
}
}