I have an authentication function which I want to detect wrong username and password condition to make a notification popup massage. I tried many codes and I find the solution but I made a new problem that won't let user log in even with correct username and password and shows the wrong identification situation, what should I do?
this is the code I wrote:
import { toast } from 'your-toast-library';
export function verifyUser(data) {
const info = new URLSearchParams();
const username = [data.username, data.captcha, data.captchaKey].join("|");
info.append("username", username);
info.append("password", data.password);
info.append("grant_type", "password");
return axios.post(config.login, info)
.then(response => {
// Check if the authentication was successful based on response structure
if (response.data && response.data.success) {
// Authentication successful
return response;
} else {
// Authentication failed, show a toast message
toast.error('Incorrect username or password');
return Promise.reject(new Error('Authentication failed'));
}
})
.catch(error => {
// Handle other errors if needed
return Promise.reject(error);
});
}