src/Web/User.php
public function logout($destroySession = true)
    {
        $identity = $this->getIdentity();
        if ($identity === null) {
            return $this->getIsGuest() ? resolve(true) : reject(false);
        }

        //Using root resolve function for promise conversion
        return resolve(true)
            ->then(function() use (&$identity) { return $this->beforeLogout($identity); })
            ->then(function() use (&$identity, $destroySession) {
                $this->switchIdentity(null);
                $id = $identity->getId();
                $ip = $this->request->getUserIP();
                Reaction::info("User '$id' logged out from $ip.");
                if ($destroySession && $this->enableSession) {
                    return $this->app->session->destroy();
                } else {
                    return true;
                }
            })->always(function() use (&$identity) {
                return $this->afterLogout($identity);
            })->then(function() use (&$identity) {
                return $this->getIsGuest() ? true : reject("User logout failed");
            });
    }
public function logout($destroySession = true)
    {
        $identity = $this->getIdentity();
        if ($identity === null) {
            return $this->getIsGuest() ? resolve(true) : reject(false);
        }

        //Using root resolve function for promise conversion
        return resolve(true)
            ->then(function() use (&$identity) { return $this->beforeLogout($identity); })
            ->then(function() use (&$identity, $destroySession) {
                $this->switchIdentity(null);
                $id = $identity->getId();
                $ip = $this->request->getUserIP();
                Reaction::info("User '$id' logged out from $ip.");
                if ($destroySession && $this->enableSession) {
                    return $this->app->session->destroy();
                } else {
                    return true;
                }
            })->always(function() use (&$identity) {
                return $this->afterLogout($identity);
            })->then(function() use (&$identity) {
                return $this->getIsGuest() ? true : reject("User logout failed");
            });
    }
Logs out the current user.
This will remove authentication-related session data.
If `$destroySession` is true, all session data will be removed.
@param bool $destroySession whether to destroy the whole session. Defaults to true.
This parameter is ignored if [[enableSession]] is false.
@return ExtendedPromiseInterface with bool whether the user is logged out
@throws \Throwable