async checkRights(request) {
    if (
      !global.kuzzle.config.http.cookieAuthentication &&
      request.getBoolean("cookieAuth")
    ) {
      throw kerror.get("security", "cookie", "unsupported");
    }

    let skipTokenVerification = false;
    // When the Support of Cookie as Authentication Token is enabled we check if an auth token cookie is present
    // When a request is made with cookieAuth set to true
    // We try to use the auth token cookie if present as auth token
    // otherwise check for auth token as input
    if (request.input.headers && has(request.input.headers, "cookie")) {
      let cookie;
      try {
        cookie = Cookie.parse(request.input.headers.cookie);
      } catch (error) {
        throw kerror.get("security", "cookie", "invalid");
      }

      // if cookie is present and not null, and a token is present we should throw because we don't know which one to use
      if (cookie.authToken && cookie.authToken !== "null") {
        if (!global.kuzzle.config.http.cookieAuthentication) {
          throw kerror.get("security", "cookie", "unsupported");
        }

        if (request.input.jwt) {
          throw kerror.get(
            "security",
            "token",
            "verification_error",
            "Both token and cookie are present, could not decide which one to use",
          );
        }

        request.input.jwt = cookie.authToken;

        skipTokenVerification =
          request.getBoolean("cookieAuth") &&
          request.input.controller === "auth" &&
          SKIP_TOKEN_VERIF_ACTIONS.includes(request.input.action);
      }
    }

    try {
      // If the verification should be skipped, we pass a null token,
      // this way the verification will be made as anonymous
      const token = skipTokenVerification ? null : request.input.jwt;

      request.context.token = await global.kuzzle.ask(
        "core:security:token:verify",
        token,
      );
    } catch (error) {
      await global.kuzzle.pipe("request:onUnauthorized", request);
      throw error;
    }

    const userId = request.context.token.userId;

    request.context.user = await global.kuzzle.ask(
      "core:security:user:get",
      userId,
    );

    // If we have a token, link the connection with the token,
    // this way the connection can be notified when the token has expired.
    if (
      global.kuzzle.config.internal.notifiableProtocols.includes(
        request.context.connection.protocol,
      )
    ) {
      global.kuzzle.tokenManager.link(
        request.context.token,
        request.context.connection.id,
      );
    }

    if (!(await request.context.user.isActionAllowed(request))) {
      // anonymous user => 401 (Unauthorized) error
      // logged-in user with insufficient permissions => 403 (Forbidden) error
      const error = kerror.get(
        "security",
        "rights",
        userId === "-1" ? "unauthorized" : "forbidden",
        request.input.controller,
        request.input.action,
        request.context.user._id,
      );

      request.setError(error);

      await global.kuzzle.pipe("request:onUnauthorized", request);
      throw error;
    }

    if (
      global.kuzzle.config.plugins.common.failsafeMode &&
      !this._isLogin(request) &&
      !request.context.user.profileIds.includes("admin")
    ) {
      await global.kuzzle.pipe("request:onUnauthorized", request);
      throw kerror.get("security", "rights", "failsafe_mode_admin_only");
    }

    return global.kuzzle.pipe("request:onAuthorized", request);
  }
Checks if a user has the necessary rights to execute the action

@param {Request} request
@returns {Promise<Request>}