auth method

Future<UserReference> auth({
  1. String? alias,
  2. String? password,
  3. PairReturnType? pair,
  4. LoginCallback? cb,
  5. dynamic opt = DEFAULT_AUTH_OPTS,
})

https://gun.eco/docs/User#user-auth

@param alias @param password @param pair @param cb @param opt

Implementation

Future<UserReference> auth(
    {String? alias,
    String? password,
    PairReturnType? pair,
    LoginCallback? cb,
    opt = DEFAULT_AUTH_OPTS}) async {
  if ((alias == null || password == null) && pair == null) {
    throw ("Either Enter Pair or User alias and pass");
  }

  alias ??= pair!.pub;
  password ??= pair!.epriv;

  try {
    final user = await authenticate(_client, alias, password);
    final ref = useCredentials(UserCredentials.fromJson(user.toJson()));
    if (cb != null) {
      cb(ref);
    }
    return ref;
  } catch (err) {
    if (cb != null) {
      cb({err});
    }
    throw (err.toString());
  }
}