Add dedicated users/me route using payload.auth

This commit is contained in:
Enguerrand Ozano
2026-03-01 12:11:21 +01:00
parent ac4a88d08b
commit e69fa0fff2
4 changed files with 81 additions and 47 deletions

View File

@@ -1,25 +0,0 @@
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 },
);
}
}