post<T extends ToJson> method
Null safety
- T payload
Posts the authentication request to the server
Implementation
Future<AuthToken> post<T extends ToJson>(T payload) async {
const errMessage = 'Error while authenticating, please try again. '
'If this persists please contact App Support.';
final authClient = Get.find<AuthRestClient>().client;
try {
final response = await authClient.post(null, endpoint: endpoint, body: payload.toJson());
final Map<String, dynamic> data = jsonDecode(response.body);
return response.isSuccessful()
? AuthToken.fromJson(data)
: AuthToken.failed(data.isNotEmpty && data['message'] != null ? data['message'] : errMessage);
} on Exception {
return AuthToken.failed(errMessage);
}
}