    <script type="text/javascript">
        (function () {
            const signInPageUrl = 'https://landing-like-prod.monocrm.dev/sign-in';
            const cookieAttrs = 'path=/; SameSite=Lax; Secure';
            const LOGOUT_KEY = 'cp_crm_logout';

            const urlParams = new URLSearchParams(window.location.search);
            const redirectTo = urlParams.get('redirectTo') || '';

            function getCookie(name) {
                const parts = ('; ' + document.cookie).split('; ' + name + '=');
                if (parts.length === 2) return decodeURIComponent(parts.pop().split(';').shift());
                return '';
            }

            if (redirectTo) {
                document.cookie = 'crm-redirect-to=' + encodeURIComponent(redirectTo)
                    + '; Max-Age=' + (24 * 60 * 60) + '; ' + cookieAttrs;
            }

            function clearStorage() {
                try { localStorage.removeItem('@storage'); } catch (e) {}
                if (typeof window.cpCrmApplyAuthUi === 'function') {
                    window.cpCrmApplyAuthUi();
                }
            }

            function hasStorageToken() {
                try {
                    const data = JSON.parse(localStorage.getItem('@storage') || '{}');
                    return Boolean(data && data.token);
                } catch (e) {
                    return false;
                }
            }

            function portalHash() {
                const path = (redirectTo || getCookie('crm-redirect-to') || '/finance/deposit').replace(/^#/, '');
                return '#' + (path.charAt(0) === '/' ? path : '/' + path);
            }

            /** Wipe JWT + cookies and tell every other tab to do the same. */
            function logoutEverywhere() {
                clearStorage();
                try { localStorage.setItem(LOGOUT_KEY, String(Date.now())); } catch (e) {}

                const form = new FormData();
                form.append('action', 'logout');
                fetch('/wp-admin/admin-ajax.php', { method: 'POST', body: form, keepalive: true });

                document.cookie = 'crm-lang=; Max-Age=-99999999; ' + cookieAttrs;
                document.cookie = 'crm-redirect-to=; Max-Age=-99999999; ' + cookieAttrs;
                location.href = signInPageUrl;
            }

            function onAuthHash() {
                const path = location.hash.split('?')[0];

                if (path === '#/logout') {
                    logoutEverywhere();
                    return;
                }

                // Empty CP route. Token present (AutoSignIn / other tab) → open portal.
                // No token → full logout so UI and storage stay in sync.
                if (path === '#/sign-in') {
                    if (hasStorageToken()) {
                        const next = portalHash();
                        if (location.hash !== next) {
                            location.replace(location.pathname + location.search + next);
                            location.reload();
                        }
                    } else {
                        logoutEverywhere();
                    }
                }
            }

            onAuthHash();
            window.addEventListener('hashchange', onAuthHash);
            window.addEventListener('popstate', onAuthHash);
            // parent-iframe-window / hash nav may use history APIs.
            ['pushState', 'replaceState'].forEach(function (method) {
                const original = history[method];
                history[method] = function () {
                    const result = original.apply(this, arguments);
                    onAuthHash();
                    return result;
                };
            });

                        // Keep #/authorization intact so the first login can store the JWT.
            if (!location.hash.startsWith('#/authorization') && !hasStorageToken()) {
                location.hash = '#/logout';
            }
                    })();
    </script>

    <div
        id="client-portal-iframe"
        data-url="https://client-portal-iframe.vectorshiftsup.top"
        data-brand="dobby"
    ></div>

    <div id="cp-widget">
        <div id="support-btn">
            <div class="support-btn__outer"></div>
            <div class="support-btn__outer_2"></div>
            <a id="support-callback" class="support-services" href="#/callback-request">
                <img src="https://landing-like-prod.monocrm.dev/wp-content/plugins/cp-crm-integration/assets/images/support.svg" alt="">
            </a>
        </div>
    </div>
    {"id":10999,"date":"2022-01-05T17:38:45","date_gmt":"2022-01-05T16:38:45","guid":{"rendered":"https:\/\/landing-like-prod.monocrm.dev\/?page_id=10999"},"modified":"2025-06-17T17:15:04","modified_gmt":"2025-06-17T16:15:04","slug":"client-portal","status":"publish","type":"page","link":"https:\/\/landing-like-prod.monocrm.dev\/de\/client-portal","title":{"rendered":"Client Portal"},"content":{"rendered":"\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-10999","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/pages\/10999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/comments?post=10999"}],"version-history":[{"count":1,"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/pages\/10999\/revisions"}],"predecessor-version":[{"id":11000,"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/pages\/10999\/revisions\/11000"}],"wp:attachment":[{"href":"https:\/\/landing-like-prod.monocrm.dev\/de\/wp-json\/wp\/v2\/media?parent=10999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}