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 on your feathers js server

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 {
  if (this.client == 'rest') {
    return await standaloneRest!.authenticate(
        strategy: strategy,
        userName: userName,
        userNameFieldName: userNameFieldName,
        password: password);
  } else if (this.client == 'socketio') {
    return await standaloneSocketio!.authenticate(
        strategy: strategy,
        userName: userName,
        userNameFieldName: userNameFieldName,
        password: password);
  }

  // If no client is set, use the default one
  try {
    //Auth with rest to refresh or create new accessToken
    var restAuthResponse = await rest.authenticate(
        strategy: strategy,
        userName: userName,
        userNameFieldName: userNameFieldName,
        password: password);

    try {
      //Then auth with jwt socketio
      bool isAuthenticated = await scketio.authWithJWT();

      // Check wether both client are authenticated or not
      if (restAuthResponse != null && isAuthenticated == true) {
        return restAuthResponse;
      } else {
        // Both failed
        throw new FeatherJsError(
            type: FeatherJsErrorType.IS_AUTH_FAILED_ERROR,
            error: "Auth failed with unknown reason");
      }
    } on FeatherJsError catch (e) {
      // Socketio failed
      throw new FeatherJsError(type: e.type, error: e);
    }
  } on FeatherJsError catch (e) {
    // Rest failed
    throw new FeatherJsError(type: e.type, error: e);
  }
}