postToken method
Requests jwt token TokenResponse
from server.
Requires email
and password
. Returns player object TokenResponse
in case of success
Throws DioError
in case of network connection problems or
null in case of Unauthorised server response
Implementation
Future<TokenResponse?> postToken(String email, String password) async {
try {
final Response<String> response = await _dio.post('/authentication_token',
data: TokenRequest(email: email, password: password).toRawJson());
return TokenResponse.fromRawJson(response.data!);
} on DioError catch (e) {
if (e.response?.statusCode == 401) {
return null;
} else {
rethrow;
}
}
}