javascript - 如何在节点登录 API 中添加角色或映射电子邮件、密码和角色?
问题描述
当我提供正确的凭据时,我的登录 API 正在生成令牌,现在我想添加角色并通过将电子邮件、密码与角色(即)用户或管理员映射来检查它是否生成令牌。我将如何实现这一点。下面是我的代码.我从员工表中获取电子邮件和密码,并希望从角色表中映射角色。期待帮助
getUserByUserEmail : (email , callBack) =>{
pool.query(
`select * from employee inner join roles on employee.internal_id = roles.internal_id where email = ?`,
[email],
(error, results, fields) => {
if(error){
return callBack(error);
}
return callBack(null, results);
}
)
}
这是我调用 getUserByUserEmail 服务的登录功能。
login: (req, res ) =>{
const body = req.body;
getUserByUserEmail(body.email, (err, results) => {
if(err) {
console.log(err);
}
if(!results) {
return res.json({
success : 0 ,
message : "Invalid Email or Password"
});
}
const result = compareSync( body.password, results[0].password);
if (result) {
results[0].password = "";
const jsontoken = sign({ result: results }, "qwe123", {expiresIn : "3h"});
return res.json({
success : 1 ,
message : "You are logged in Successfully!",
token : jsontoken
});
console.log(results)
}
else{
return res.json({
success : 0 ,
message : "Invalid Email or Password"
});
}
});
}
解决方案
推荐阅读
- elasticsearch - 如何从elasticsearch中的结果集中搜索结果集
- python - 在 Python 中填充列表的一部分/等效于 std::fill
- java - 两个 64 位数字相乘_Gettin Input Mismatch Exception
- android - 无法初始化类 org.codehaus.groovy.reflection.ReflectionCache #Ubuntu #flutter #androidStudio
- c# - 如何使用 pInvoke 在 Windows 中检测物理设备是在线还是离线
- docker - 运行(docker_image)模块ansible Playbook时出错
- django - 未找到带有参数“(”,)”的“update_laptop”的反向操作。尝试了 1 种模式:['update_laptop/(?P
[^/]+)/$'] - java - Android CardView 实现
- sql - 执行错误:[Vertica][VJDBC](4856) 错误:“.”处或附近的语法错误
- tensorflow - TFJS 预测与 Python 预测