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.
upload-file-backend/src/api/controllers/v1/auth.controller.js

33 lines
902 B

2 years ago
import messages from '../../../config/messages';
import { handler as ErrorHandler } from '../../middlewares/error';
import User from '../../../common/models/user.model';
exports.register = async (req, res, next) => {
const user = new User(
req.body
);
user.save()
.then(data => {
res.json({
code: 0,
message: messages.CREATE_SUCCESS,
data: User.transform(data)
});
}).catch(ex => {
ErrorHandler(ex, req, res, next);
});
};
exports.login = async (req, res, next) => {
res.json({
code: 0,
message: null,
data: { token: req.locals.token, user: req.locals.user }
});
};
exports.loginToken = async (req, res, next) => res.json({
code: 0,
message: messages.CREATE_SUCCESS,
data: { token: req.locals.token, data: req.locals.user }
});