-3
my problem is the following I am trying to put my login with various levels of access as if it is level 1 enters as super administrator if it is 2 enters as administrator and if it is 3 enters as employee I’m using angular 7 nodejs and mongodb the code is followed auth.service.ts
`getUserDetails(username,password){ return this.http.post('api/login',{ username, password }`) }
login Component
login() {
let username = this.loginForm.value.username;
let password = this.loginForm.value.password;
this.Auth.getUserDetails(username,password).subscribe(data =>{
if(data.success){
this.router.navigate(['homepage'])
this.Auth.setLoggedIn(true)
//sdsadad
}else{
document.getElementById("erro").style.visibility = "visible";
window.setTimeout("location.href='login'",3000);
}
})
}
nodejs
app.post('/api/login', async (req,res)=>{
const {username,password}=req.body
const resp = await User.findOne({ username: username}).select('+password')
if(password==null){
res.json({success:false,
message:" password can not be empty"
})
}else if(username==null){
res.json({success:false,
message:" username can not be empty "
})
}
else if(!resp){
res.json({success:false,
message:"incorrect password"
})
}
else if(!await bcrypt.compare(password, resp.password)){
//if(!resp){
res.json({success:false,
message:"incorrect password"
})
}else {
///sessions
req.session.user=username
req.session.save()
res.json({
success:true
})
}
})
what I have to change the complete code is on this link https://github.com/Kammikazy/project
what the problem or error?
– Eduardo Vargas
the problem is I don’t know what I have to change in my code
– Pedro
In this case your question is very generic pro stackoverflow, has a thousand ways to have this behavior. One of them would be to return a user object and there vc do the logics of access
– Eduardo Vargas