Skip to content

Commit

Permalink
bg[161364709] Correct error in verify admin middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenezerdon committed Oct 21, 2018
1 parent 075f92f commit 0b911e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 9 additions & 10 deletions server/middleware/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,38 @@ class verify {
}
return next();
}

static Admin(req, res, next) {
const token = req.headers.accesstoken;
jwt.verify(token, secret, function (err, authdata) {
jwt.verify(token, secret, (err, authdata) => {
if (err) {
return console.log('ERROR: ', err);
}
if (authdata.type !== 'admin') {
return res.status(401).json({
message: 'Hi! This resource can only be accessed by an admin',
error: true
error: true,
});
} else {
return next();
}
return next();
});
}

static Attendant(req, res, next) {
const token = req.headers.accesstoken;
jwt.verify(token, secret, function (err, authdata) {
jwt.verify(token, secret, (err, authdata) => {
if (err) {
return console.log('ERROR: ', err);
}
if (authdata.type !== 'admin') {
if (authdata.type !== 'attendant') {
return res.status(401).json({
message: 'Hi! This resource can only be accessed by an attendant',
error: true
error: true,
});
} else {
return next();
}
return next();
});
}
}

export default verify;
export default verify;
12 changes: 6 additions & 6 deletions server/tests/sales.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ describe('Create New sale', () => {
it('create a new sale', (done) => {
chai.request(app).post('/api/v1/login')
.send({
emailAdress: 'sarahbeth@gmail.com',
password: 'supersecretstuff',
type: 'admin',
emailAdress: 'joshodogwu@gmail.com',
password: 'realsecret',
type: 'attendant',
})
.end((err, res) => {
const { token } = res.body;
Expand All @@ -115,9 +115,9 @@ describe('Create New sale', () => {
it('it should return error if req has no data', (done) => {
chai.request(app).post('/api/v1/login')
.send({
emailAdress: 'sarahbeth@gmail.com',
password: 'supersecretstuff',
type: 'admin',
emailAdress: 'joshodogwu@gmail.com',
password: 'realsecret',
type: 'attendant',
})
.end((err, res) => {
const { token } = res.body;
Expand Down

0 comments on commit 0b911e9

Please sign in to comment.