fix(Auth): Error type in json payload
This commit is contained in:
committed by
mrugesh mohapatra
parent
e1c5b8a894
commit
a1530c041a
@ -66,13 +66,13 @@ module.exports = function enableAuthentication(app) {
|
|||||||
const passwordlessGetValidators = [
|
const passwordlessGetValidators = [
|
||||||
check('email')
|
check('email')
|
||||||
.isBase64()
|
.isBase64()
|
||||||
.withMessage('email should be a base64 encoded string'),
|
.withMessage('Email should be a base64 encoded string.'),
|
||||||
check('token')
|
check('token')
|
||||||
.exists()
|
.exists()
|
||||||
.withMessage('token should exist')
|
.withMessage('Token should exist.')
|
||||||
// based on strongloop/loopback/common/models/access-token.js#L15
|
// based on strongloop/loopback/common/models/access-token.js#L15
|
||||||
.isLength({ min: 64, max: 64 })
|
.isLength({ min: 64, max: 64 })
|
||||||
.withMessage('token is not the right length')
|
.withMessage('Token is not the right length.')
|
||||||
];
|
];
|
||||||
|
|
||||||
function getPasswordlessAuth(req, res, next) {
|
function getPasswordlessAuth(req, res, next) {
|
||||||
@ -83,7 +83,7 @@ module.exports = function enableAuthentication(app) {
|
|||||||
} = {}
|
} = {}
|
||||||
} = req;
|
} = req;
|
||||||
const validation = validationResult(req)
|
const validation = validationResult(req)
|
||||||
.formatWith(createValidatorErrorFormatter('info', '/email-signup'));
|
.formatWith(createValidatorErrorFormatter('errors', '/email-signup'));
|
||||||
|
|
||||||
if (!validation.isEmpty()) {
|
if (!validation.isEmpty()) {
|
||||||
const errors = validation.array();
|
const errors = validation.array();
|
||||||
@ -193,12 +193,12 @@ module.exports = function enableAuthentication(app) {
|
|||||||
const passwordlessPostValidators = [
|
const passwordlessPostValidators = [
|
||||||
check('email')
|
check('email')
|
||||||
.isEmail()
|
.isEmail()
|
||||||
.withMessage('email is not a valid email address')
|
.withMessage('Email is not a valid email address.')
|
||||||
];
|
];
|
||||||
function postPasswordlessAuth(req, res, next) {
|
function postPasswordlessAuth(req, res, next) {
|
||||||
const { body: { email } = {} } = req;
|
const { body: { email } = {} } = req;
|
||||||
const validation = validationResult(req)
|
const validation = validationResult(req)
|
||||||
.formatWith(createValidatorErrorFormatter('info', '/email-signup'));
|
.formatWith(createValidatorErrorFormatter('errors', '/email-signup'));
|
||||||
if (!validation.isEmpty()) {
|
if (!validation.isEmpty()) {
|
||||||
const errors = validation.array();
|
const errors = validation.array();
|
||||||
return next(errors.pop());
|
return next(errors.pop());
|
||||||
|
@ -89,6 +89,7 @@ export default function prodErrorHandler() {
|
|||||||
} else if (type === 'json') {
|
} else if (type === 'json') {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
return res.send({
|
return res.send({
|
||||||
|
type: handled.type || 'errors',
|
||||||
message
|
message
|
||||||
});
|
});
|
||||||
// plain text
|
// plain text
|
||||||
|
@ -74,11 +74,25 @@ block content
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.done(data =>{
|
.done(data =>{
|
||||||
if(data && data.message){
|
if(data && data.message) {
|
||||||
|
var alertType = 'alert-';
|
||||||
|
switch (data.type) {
|
||||||
|
case 'errors': {
|
||||||
|
alertType += 'danger';
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'success': {
|
||||||
|
alertType += 'success';
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
alertType += 'info';
|
||||||
|
}
|
||||||
|
}
|
||||||
$('#flash-content').html(data.message);
|
$('#flash-content').html(data.message);
|
||||||
$('#flash-board')
|
$('#flash-board')
|
||||||
.removeClass('alert-info')
|
.removeClass('alert-info alert-success alert-error')
|
||||||
.addClass('alert-success')
|
.addClass(alertType)
|
||||||
.fadeIn();
|
.fadeIn();
|
||||||
disableMagicButton(false);
|
disableMagicButton(false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user