loginWithCredentials method
Future<Either<Failure, AuthenticationData>>
loginWithCredentials(
- String username,
- String password
)
inherited
Implementation
@override
Future<Either<Failure, AuthenticationData>> loginWithCredentials(String username, String password) async {
AuthenticationData authData;
AuthDeviceInfo? authDeviceInfo;
return wrapAndHandleHttpBaseRequest(
() async {
final url = config.loginCredentialsAPIendpoint();
authDeviceInfo = config.provideDeviceInfo ? await AuthDeviceInfoModel.create() : null;
final requestBody = jsonEncode(
config.customLoginRequestMapper != null
? (await config.customLoginRequestMapper!(
username,
password,
authDeviceInfo,
))
: {
"email": username,
"password": password,
if (authDeviceInfo != null) "deviceInfo": authDeviceInfo!.toMap(),
},
);
logger.v("Login with credentials: $username|$password at API: $url");
final request = Request(
"POST",
url,
)..body = requestBody;
return request;
},
onResponse: (response, left, right) async {
if (config.customLoginResponseParser != null) {
authData = await config.customLoginResponseParser!(response.body);
} else {
authData = defaultAuthenticationDataParser(response.body)!;
}
await storeAuthDataSession(authData.copyWith(deviceInfo: authDeviceInfo));
logger.v("Login successfully");
return right(
authData,
);
},
);
}