mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
working
This commit is contained in:
30
backend/routes/auth.js
Normal file
30
backend/routes/auth.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const express = require("express");
|
||||
const { body } = require("express-validator");
|
||||
const User = require("../models/User");
|
||||
const authController = require("../controllers/auth");
|
||||
|
||||
const routes = express.Router();
|
||||
|
||||
routes.put(
|
||||
"/signup",
|
||||
[
|
||||
body("email")
|
||||
.isEmail()
|
||||
.withMessage("Email inválido")
|
||||
.custom((value, { req }) => {
|
||||
return User.findOne({ where: { email: value } }).then(user => {
|
||||
if (user) {
|
||||
return Promise.reject("Um cadastro com este email já existe!");
|
||||
}
|
||||
});
|
||||
})
|
||||
.normalizeEmail(),
|
||||
body("password").trim().isLength({ min: 5 }),
|
||||
body("name").trim().not().isEmpty(),
|
||||
],
|
||||
authController.signup
|
||||
);
|
||||
|
||||
routes.post("/login", authController.login);
|
||||
|
||||
module.exports = routes;
|
||||
Reference in New Issue
Block a user