reAuthenticate method
Authenticate rest and scketio clients so you can use both of them
Implementation
Future<Map<String, dynamic>> reAuthenticate() async {
//Hold global auth infos
Map<String, dynamic> authResponse = {
"error": true,
"error_zone": Constants.UNKNOWN_ERROR,
"message": "An error occured either on rest or socketio auth",
"restResponse": {},
"scketResponse": {}
};
//Auth with rest to refresh or create accessToken
Map<String, dynamic> restAuthResponse = await rest.reAuthenticate();
//Then auth with jwt socketio
Map<String, dynamic> socketioAuthResponse = await scketio.authWithJWT();
//Finally send response
if (!restAuthResponse["error"] && !socketioAuthResponse["error"]) {
authResponse["error"] = false;
authResponse["error_zone"] = Constants.BOTH_CLIENT_AUTHED;
authResponse["message"] = socketioAuthResponse["message"];
} else {
authResponse["error"] = true;
authResponse["error_zone"] = Constants.ONE_OR_BOTH_CLIENT_NOT_AUTHED;
authResponse["message"] =
"One or both client is(are) not authed. Please checkout restResponse field or scketResponse field for more infos.";
authResponse["restResponse"] = restAuthResponse;
authResponse["scketResponse"] = socketioAuthResponse;
}
return authResponse;
}