0

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);
        });
}
2
  • solved. I added a errormsg in helper api file and then i imported it inside apiService and it fixed Commented Aug 26, 2023 at 12:20
  • the title should describe the problem ... please edit it Commented Aug 27, 2023 at 18:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.