import { authenticateAdmin } from '../../../lib/authenticate' import withSession from '../../../lib/session' async function loginHandler(req: any, res: any): Promise { const { method } = req switch (method) { case 'POST': const { username, password } = req.body if (!authenticateAdmin({ username, password })) { res.status(401).end() return } const userData = { username, role: 'admin' } req.session.set('user', userData) await req.session.save() res.json({ message: 'Authenticated', user: userData }) break default: res.setHeader('Allow', ['POST']) res.status(405).end(`Method ${method} Not Allowed`) } } export default withSession(loginHandler)