here is my html code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="script.js"></script> <title>Document</title> </head> <body> <form action="/login" method="post"> <input name="username" type="text" placeholder="username"> <input name="password" type="password" placeholder="password"> <button type="submit">Login</button> </form> </body> </html>
and this is my server side code:
app.get('/login', (req, res) => { res.sendFile(__dirname + '/login.html') }) app.post('/login', (req, res) => { const { username, password } = req.body const foundUser = users.find(u => { return u.username === username }) if(foundUser.password !== password) { res.send('wrong password') } else { const accessToken = jwt.sign({ username: foundUser.username, password: foundUser.password }, jwtSecret) res.json({ accessToken: accessToken }) } }) <pre lang="text">so after I make a post request to /login route and log in, my server will respond with some JSON data but I'm not sure how to get or access that data from the client side. should I do it from script.js? if so how should I do it? I would appreciate any help
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)