login(data: any) {
this.user.getUsers().subscribe(
(users) => {
const user = users.find((u) => u.username === data.username && u.userpassword === data.password);
if (user) {
// Valid username and password, navigate to the dashboard
this.route.navigate(['dashboard']);
} else {
// Invalid username or password, handle accordingly (e.g., show an error message)
console.error('Invalid username or password');
}
},
(error) => {
console.error('Error fetching users:', error);
}
);
}
I encountered a problem with this code where the subscriber is deprecated, and after clicking the login button, it fails to open the dashboard page.
To resolve this issue, I am looking for a way to only allow successful logins with data that matches entries in a JSON file, which will then automatically navigate to the dashboard page.