-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
29 lines (22 loc) · 703 Bytes
/
auth.js
File metadata and controls
29 lines (22 loc) · 703 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
28
29
const errors = require('restify-errors');
const User = require('./models/User');
const bcrypt = require('bcryptjs');
exports.authentication = (email, password) => {
return new Promise(async (resolve, reject) => {
try {
const user = await User.findOne({email});
bcrypt.compare(password, user.password, (err, isMatch) => {
if (err) {
// throw err;
}
if (isMatch) {
resolve(user);
} else {
reject('password not match');
}
});
} catch (e) {
reject('Authentication fail');
}
});
}