-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestauth.js
More file actions
61 lines (45 loc) · 1.11 KB
/
testauth.js
File metadata and controls
61 lines (45 loc) · 1.11 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* @Author: AJ Javadi
* @Email: amirjavadi25@gmail.com
* @Date: 2023-07-31 10:07:57
* @Last Modified by: Someone
* @Last Modified time: 2023-07-31 10:08:24
* @Description: loginfeature
*/
const express = require('express');
const dotenv = require('dotenv');
const jwt = require('jsonwebtoken');
app = express();
app.get('/', (req, res) => {
res.send("hello")
});
// app.get()
users = [
{
username: 'testuser1',
password: '123456'
},
{
username: 'testuser2',
password: '123456'
}
]
// create a function that tests if the user is valid
const authenticateUser = (req, res, next) => {
const username = req.body.username;
const user = { name: username };
// create a token
const accessToken = jwt.sign(user, process.env.ACCESS_TOKEN_SECRET);
res.json({ accessToken: accessToken });
next();
}
// app.post('/login', (req, res) => {
// // Authenticate User
// const username = req.body.username;
// const user = { name: username };
// }
// test listen
app.listen(3000, () => {
console.log("hello")
}
) // end of app.listen