-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.controller.js
More file actions
27 lines (24 loc) · 689 Bytes
/
auth.controller.js
File metadata and controls
27 lines (24 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Created by KD
*/
const jwt = require('jsonwebtoken');
const httpStatus = require('http-status');
const user = require('../user/user.helper');
function login(req, res) {
user.getByUsernamePassword(req.body.username, req.body.password)
.then(user => {
if (!user) {
return res.status(httpStatus.UNAUTHORIZED).send({msg: 'Unauthorized'});
}
let token = jwt.sign({username: user.username}, process.env.APP_SECRET, {
expiresIn: process.env.JWT_EXPIRES_IN
});
return res.send({token: token});
})
.catch(error => {
return res.status(httpStatus.INTERNAL_SERVER_ERROR).send(error)
});
};
module.exports = {
login
};