auth.routes.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const asyncHandler = require("express-async-handler");
  2. const { Router } = require("express");
  3. const validators = require("../handlers/validators.handler");
  4. const helpers = require("../handlers/helpers.handler");
  5. const auth = require("../handlers/auth.handler");
  6. const utils = require("../utils");
  7. const router = Router();
  8. router.post(
  9. "/login",
  10. helpers.viewTemplate("partials/auth/form"),
  11. validators.login,
  12. asyncHandler(helpers.verify),
  13. asyncHandler(auth.local),
  14. asyncHandler(auth.login)
  15. );
  16. router.post(
  17. "/signup",
  18. helpers.viewTemplate("partials/auth/form"),
  19. auth.signupAccess,
  20. validators.signup,
  21. asyncHandler(helpers.verify),
  22. asyncHandler(auth.signup)
  23. );
  24. // router.post("/renew", asyncHandler(auth.jwt), asyncHandler(auth.token));
  25. router.post(
  26. "/change-password",
  27. helpers.viewTemplate("partials/settings/change_password"),
  28. asyncHandler(auth.jwt),
  29. validators.changePassword,
  30. asyncHandler(helpers.verify),
  31. asyncHandler(auth.changePassword)
  32. );
  33. router.post(
  34. "/change-email",
  35. helpers.viewTemplate("partials/settings/change_email"),
  36. asyncHandler(auth.jwt),
  37. validators.changeEmail,
  38. asyncHandler(helpers.verify),
  39. asyncHandler(auth.changeEmailRequest)
  40. );
  41. router.post(
  42. "/apikey",
  43. helpers.viewTemplate("partials/settings/apikey"),
  44. asyncHandler(auth.jwt),
  45. asyncHandler(auth.generateApiKey)
  46. );
  47. router.post(
  48. "/reset-password",
  49. helpers.viewTemplate("partials/reset_password/form"),
  50. validators.resetPassword,
  51. asyncHandler(helpers.verify),
  52. asyncHandler(auth.resetPasswordRequest)
  53. );
  54. module.exports = router;