login.ts 712 B

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