register method

Future<void> register({
  1. UserPassword? password,
  2. UserLogin? login,
  3. bool force = false,
})

Creates a new MyUser having only UserId and UserNum fields, and creates a new Session for this MyUser (valid for 24 hours).

Once the created Session expires, the created MyUser looses access, if he doesn't re-sign in within that period of time.

If status is already authorized, then this method does nothing, however, this logic can be ignored by specifying force as true.

Implementation

Future<void> register({
  UserPassword? password,
  UserLogin? login,
  bool force = false,
}) async {
  Log.debug('register(force: $force)', '$runtimeType');

  status.value = force ? RxStatus.loadingMore() : RxStatus.loading();

  await WebUtils.protect(() async {
    if (isClosed) {
      return;
    }

    // If service is already authorized, then no-op, as this operation is
    // meant to be invoked only during unauthorized phase or account
    // switching, or otherwise the dependencies will be broken as of now.
    if (!force && _hasAuthorization) {
      return;
    }

    try {
      final Credentials data = await _authRepository.signUp(
        login: login,
        password: password,
      );
      await _authorized(data);
      status.value = RxStatus.success();
    } catch (e) {
      if (force) {
        status.value = RxStatus.success();
      } else {
        _unauthorized();
      }
      rethrow;
    }
  });
}