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.
CodePudding user response:
Usually to identify what happened in backend we send a HTTP code along with some kind of data/message in the body.
CodePudding user response:
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}),
);
}