skip to Main Content

If return 401 (Unauthorized), I don’t know password field is wrong or username is wrong in frontend.
Which code should return for password wrong? and which code for username wrong?

I wanna know exactly which field is wrong in authentication.

2

Answers


  1. Usually to identify what happened in backend we send a HTTP code along with some kind of data/message in the body.

    Login or Signup to reply.
  2. You can simply print parameters value which you send to the Api for better understanding which you send and which response you get. And please make a validation in Email and Password TextFormField because when email and password pattern perfect that after you can send a post request to the backend so you get less error.

    Code for parameter printing:

    Future<http.Response> createUser(String email, String password) {
    //Print parameters here for better understanding:
    print('params===>{$email && $password}'); 
    
    return http.post(
    Uri.parse('https://reqres.in/api/users'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{'name': email, 'job': password}),
     );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search