login method
Performs the login using username, password and one of twoFactorCode or deviceCode. If none is provided a MissingFieldsException is thrown
Implementation
Future<LoginData> login(String username, String password, {String? twoFactorCode, String? deviceCode}) async {
_JinyaResponse? response;
if (deviceCode != null) {
response = await _post(
'/api/login',
data: {'username': username, 'password': password},
additionalHeaders: {'JinyaDeviceCode': deviceCode},
);
} else if (twoFactorCode != null) {
response = await _post(
'/api/login',
data: {'username': username, 'password': password, 'twoFactorCode': twoFactorCode},
);
}
if (response != null) {
return LoginData.fromJson(response.data);
}
throw MissingFieldsException(['twoFactorCode']);
}