authenticate method

Future<Map<String, dynamic>> authenticate (
  1. {String strategy: "local",
  2. @required String userName,
  3. @required String password,
  4. String userNameFieldName: "email"}
)

Authenticate rest and scketio clients so you can use both of them


@params username can be : email, phone, etc;

But ensure that userNameFieldName is correct with your chosed strategy

By default this will be emailand the strategy local

Implementation

Future<Map<String, dynamic>> authenticate(
    {String strategy = "local",
    @required String userName,
    @required String password,
    String userNameFieldName = "email"}) async {
  //Hold global auth infos
  Map<String, dynamic> authResponse = {
    "error": true,
    "error_zone": "UNKNOWN",
    "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.authenticate(
      strategy: strategy,
      userName: userName,
      userNameFieldName: userNameFieldName,
      password: password);
  //Then auth with jwt socketio
  Map<String, dynamic> socketioAuthResponse = await scketio.authWithJWT();

  //Finally send response
  if (!restAuthResponse["error"] && !socketioAuthResponse["error"]) {
    authResponse = restAuthResponse;
  } else {
    authResponse["restResponse"] = restAuthResponse;
    authResponse["scketResponse"] = socketioAuthResponse;
  }
  return authResponse;
}