File size: 945 Bytes
eaab0a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import { NextRequest, NextResponse } from 'next/server';
import { withDb } from '@/lib/api-handler';
import { getCookieToken, getSessionUser } from '@/lib/auth';
async function handler(request: NextRequest) {
try {
const token = getCookieToken(request);
if (!token) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
const user = await getSessionUser(token);
if (!user) {
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
return NextResponse.json({
user: {
id: user.id,
email: user.email,
name: user.name,
plan: user.plan,
apiKey: user.apiKey,
createdAt: user.createdAt,
},
});
} catch (error) {
console.error('[ME_ERROR]', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}
export const GET = withDb(handler); |