-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.service.js
More file actions
27 lines (23 loc) · 782 Bytes
/
app.service.js
File metadata and controls
27 lines (23 loc) · 782 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
const jwt = require('jsonwebtoken');
const secretKey = 'Sample'
const users = [
{ id: 1, username: 'admin', password: 'admin', firstName: 'Admin', lastName: 'User', role: 'Admin' },
{ id: 2, username: 'user', password: 'user', firstName: 'Normal', lastName: 'User', role: 'User' }
];
module.exports = {
handleAuthenticateRequest
};
async function handleAuthenticateRequest({username, password}) {
const user = users.find(s => s.username === username && s.password === password);
if (user) {
const token = jwt.sign({
sub: user.id,
role: user.role
}, secretKey);
const { password, ...resultUser } = user;
return {
...resultUser,
token
}
}
}