signOut method

Future<void> signOut()

登出

Implementation

Future<void> signOut() async {
  final state = await this.getAuthState();

  if (state == null) {
    /// 本地没有合法的登录态, 不需要执行登出操作
    return;
  }

  if (state.authType == CloudBaseAuthType.ANONYMOUS) {
    throw CloudBaseException(
        code: CloudBaseExceptionCode.SIGN_OUT_FAILED, message: '匿名用户不支持登出操作');
  }

  final CloudBaseResponse? res = await CloudBaseRequest(super.core)
      .post('auth.logout', {'refresh_token': state.refreshToken});

  if (res == null) {
    throw CloudBaseException(
        code: CloudBaseExceptionCode.NULL_RESPONSE,
        message: "unknown error, res is null");
  }

  if (res.code != null) {
    throw CloudBaseException(code: res.code, message: res.message);
  }

  await cache.removeAllStore();
}