authenticateUserWithSocial static method

Future<void> authenticateUserWithSocial(
  1. String token,
  2. MBAuthSocialLoginType loginType, {
  3. String? name,
  4. String? surname,
  5. List<MBAuthContractAcceptanceParameter>? contracts,
  6. MBManager? manager,
})

Authenticate a user with social.

  • Parameters:
    • token: The social token.
    • loginType: The social the user used to authenticate.
    • name: Used only when logging with apple, to set the name in MBurger.
    • surname: Used only when logging with apple, to set the surname in MBurger.
    • contracts: If there are contracts in the project the user can accept/decline them and you can tell this to MBurger with this parameter.
    • manager: An optional MBManager used to make calls instead of MBManager.shared.
  • Returns a Future that completes when the user is authenticated correctly.

Implementation

static Future<void> authenticateUserWithSocial(
  String token,
  MBAuthSocialLoginType loginType, {
  String? name,
  String? surname,
  List<MBAuthContractAcceptanceParameter>? contracts,
  MBManager? manager,
}) {
  Map<String, String> parameters = {};
  if (loginType == MBAuthSocialLoginType.apple) {
    parameters['mode'] = 'apple';
    parameters['apple_token'] = token;
  } else if (loginType == MBAuthSocialLoginType.facebook) {
    parameters['mode'] = 'facebook';
    parameters['facebook_token'] = token;
  } else if (loginType == MBAuthSocialLoginType.google) {
    parameters['mode'] = 'google';
    parameters['google_token'] = token;
  }
  if (name != null) {
    parameters['name'] = name;
  }
  if (surname != null) {
    parameters['surname'] = surname;
  }
  if (contracts != null) {
    List<Map<String, dynamic>> contractsArray =
        contracts.map((c) => c.representation).toList();
    parameters['contracts'] = json.encode(contractsArray);
  }

  return _authenticateUserWithParameters(
    parameters,
    manager: manager,
  );
}