Next.js template
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

signup.js 627B

123456789101112131415161718192021222324252627
  1. import User from '../../../models/user';
  2. import dbConnect from '../../../utils/helpers/dbHelpers';
  3. async function handler(req, res) {
  4. const { method } = req;
  5. await dbConnect();
  6. switch (method) {
  7. case 'POST': {
  8. try {
  9. const user = await User.create(req.body);
  10. res
  11. .status(201)
  12. .json({ message: `User (${user.fullName}) created sucessfully!` });
  13. } catch (error) {
  14. res.status(400).json({ message: error.message });
  15. }
  16. break;
  17. }
  18. default:
  19. res.status(405).json({ message: 'Method not allowed' });
  20. break;
  21. }
  22. }
  23. export default handler;