import { NextApiResponse } from 'next';
import { AuthenticatedRequest, requireAuth } from '../../../../lib/middleware/authMiddleware';

export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
    if (req.method !== 'GET') {
        return res.status(405).json({ success: false, error: 'Method not allowed' });
    }

    // Require authentication
    const isAuthenticated = await requireAuth(req, res);
    if (!isAuthenticated) {
        return; // requireAuth already sent the response
    }

    // Return current user data
    return res.status(200).json({
        success: true,
        data: req.user
    });
}
