0

I have implemented an API with Basic Authentication

When I provide the correct username and password to the authentication, it works fine,

However, the problem is when i provide the wrong username / password to the request, how to prevent the Sign In dialog from pop-up

Here is my axios request code,

axios.post(url, {}, {
  auth: {
    'username': 'wrong username',
    'password': 'wrong password'
  }
})

How to prevent this dialog box from showing when I provide the wrong username / password

enter image description here

Ah Fook
  • 158
  • 1
  • 10
  • Found a solution https://stackoverflow.com/questions/86105/how-can-i-suppress-the-browsers-authentication-dialog – Ah Fook Sep 14 '22 at 05:07

1 Answers1

0

Not sure if this works but you can try setting this property validateStatus. It will make axios ignore error status code and just return result in response callback.


axios.post(url, {}, {
  auth: {
    'username': 'wrong username',
    'password': 'wrong password'
  },
  validateStatus: function (status) {
    return true;
  },
})
irous
  • 401
  • 3
  • 8