This commit is contained in:
David Arranz 2019-07-09 13:36:09 +02:00
parent 2250a8092a
commit 92e4ccbb3c
4 changed files with 22 additions and 7 deletions

View File

@ -9,7 +9,7 @@ module.exports = {
session: {
secret_token: process.env.SECRET_TOKEN || "B57J=7B`NQ$y98|~5;hc715bo09^5oz8NR+]n9r~215B91Nd9P%25_N6r!GHcOKp|18y5-73Dr5^@9k7n]5l<-41D1o",
token_expires_in: '5'
token_expires_in: '300'
},
server: {

View File

@ -9,7 +9,7 @@ module.exports = {
session: {
secret_token: process.env.SECRET_TOKEN || "B57J=7B`NQ$y98|~5;hc715bo09^5oz8NR+]n9r~215B91Nd9P%25_N6r!GHcOKp|18y5-73Dr5^@9k7n]5l<-41D1o",
token_expires_in: '5'
token_expires_in: '300'
},
server: {

View File

@ -39,6 +39,16 @@ async function login(req, res, next) {
}
async function register(req, res, next) {
function cleanAdminData(user) {
let cUser = user;
delete cUser.token;
delete cUser.lastLogin;
delete cUser.state;
delete cUser.createdAt;
delete cUser.updatedAt;
return cUser;
}
try {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>regsitro');
@ -63,8 +73,9 @@ async function register(req, res, next) {
const newUser = await authService.extraMethods.createUser(data);
const result = {
token: 'JWT ' + tokens.token,
user: newUser,
token: tokens.token,
refreshToken: tokens.token,
user: cleanAdminData(newUser.toJSON()),
};
console.log(result);
return controllerHelper.handleResultResponse(result, null, req.params, res, httpStatus.OK);
@ -88,7 +99,7 @@ async function regenerateToken(req, res, next) {
try {
const tokens = securityHelper.generateToken(values);
await authService.extraMethods.updateUserRefreshToken(user.id, tokens.refreshToken);
const result = { token: 'JWT ' + tokens.token };
const result = { token: tokens.token };
return controllerHelper.handleResultResponse(result, null, req.params, res, httpStatus.OK);
} catch(error) {
controllerHelper.handleErrorResponse(MODULE_NAME, regenerateToken.name, error, res);

View File

@ -20,8 +20,6 @@ routes.post('/auth',
routes.post('/register',
SchemaValidator(authValidation.RegisterInputType, true),
AccessValidator.isRegisteredUserPhone,
authController.register,
);
@ -31,6 +29,12 @@ routes.get('/pepepe', AccessValidator.isLoggedUser,
}
);
routes.get('/test_jwt', AccessValidator.isLoggedUser,
function (req, res) {
res.json({ success: 'You are authenticated with JWT!', user: req.user })
}
);
routes.post('/token',
authController.regenerateToken,
);