📌  相关文章
📜  如何在节点 js 的登录 api 中使用 jwt - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:53.263000             🧑  作者: Mango

代码示例1
app.post('/login', (req, res) => {
    // Read username and password from request body
    const { username, password } = req.body;

    // Filter user from the users array by username and password
    const user = users.find(u => { return u.username === username && u.password === password });

    if (user) {
        // Generate an access token
        const accessToken = jwt.sign({ username: user.username,  role: user.role }, accessTokenSecret);

        res.json({
            accessToken
        });
    } else {
        res.send('Username or password incorrect');
    }
});