test8 / src /app /api /auth /me /route.ts
simikkk's picture
Upload 93 files
eaab0a9 verified
Raw
History Blame Contribute Delete
945 Bytes
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);