signup.ts 794 B

1234567891011121314151617181920212223242526272829
  1. import axios from "axios";
  2. import type { NextApiHandler } from "next";
  3. const signUpHandler: NextApiHandler = async (req, res) => {
  4. try {
  5. const response = await axios.post(
  6. `${process.env.PRISMA_API}/register`,
  7. req.body,
  8. { headers: { "Content-Type": "application/json" } }
  9. );
  10. res.status(response.status).json(response.data);
  11. } catch (e) {
  12. if (axios.isAxiosError(e)) {
  13. res.status(e.response?.status || 500).json(e.response?.data);
  14. } else {
  15. console.error(
  16. `Error while trying to register: ${JSON.stringify(req.body, null, 2)}`
  17. );
  18. res
  19. .status(500)
  20. .json({
  21. message:
  22. "There was an error processing the request, please try again.",
  23. });
  24. }
  25. }
  26. };
  27. export default signUpHandler;