I am using Next.js API routes in welcome.js However, whenever I send a get request at the url, I get the "API resolved without sending a response for /api/v1/welcome, this may result in stalled requests" error.
When my partner runs the same code it works perfectly fine for him and he is able to get the data but I get the error on my end. This makes me think its not my code but maybe another problem - does anyone have any idea what the issue could be?
import { NextApiRequest, NextApiResponse } from 'next';
import { protect } from '../../../server/protect';
export default protect(function handler(
req: NextApiRequest,
res: NextApiResponse
) {
switch (req.method) {
case 'GET':
return res
.status(200)
.json(
'Thanks for applying to HackBeanpot 2048! <sample welcome message>'
);
case 'POST':
return res.status(201).send(undefined);
default:
return res.status(405).setHeader('Allow', 'GET, POST').send(undefined);
}
});
The protect function used is the following:
import { NextApiHandler } from 'next';
import { getSession } from 'next-auth/client';
export function protect(handler: NextApiHandler): NextApiHandler {
return async (req, res) => {
const session = await getSession({ req });
if (session) {
await handler(req, res);
} else {
res.status(401);
}
};
}