feat: hide "Try Demo" header button when logged in
The header demo button is now hidden via data-hide when the user has an active EncryptID session. Reacts to auth-change events so it appears on logout and disappears on login without page reload. Landing page hero CTAs already swap to "Go to My Space" when logged in. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f7ecf50588
commit
b66e9b44de
|
|
@ -55,19 +55,12 @@ function renderShellHeader(moduleId: string, modules: ModuleInfo[]): string {
|
|||
<script type="module">
|
||||
import '/shell.js';
|
||||
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
|
||||
// Logged-in users: redirect CTA to personal space
|
||||
// Logged-in users: hide header demo btn
|
||||
try {
|
||||
var raw = localStorage.getItem('encryptid_session');
|
||||
if (raw) {
|
||||
var session = JSON.parse(raw);
|
||||
if (session?.claims?.username) {
|
||||
var username = session.claims.username.toLowerCase();
|
||||
var btn = document.querySelector('.rstack-header__demo-btn');
|
||||
if (btn) {
|
||||
btn.textContent = 'Go to My Space';
|
||||
btn.href = 'https://' + username + '.rspace.online/${escapeAttr(moduleId)}';
|
||||
}
|
||||
}
|
||||
var btn = document.querySelector('.rstack-header__demo-btn');
|
||||
if (btn) btn.setAttribute('data-hide', '');
|
||||
}
|
||||
} catch(e) {}
|
||||
</script>`;
|
||||
|
|
|
|||
|
|
@ -221,11 +221,13 @@ export function renderMainLanding(modules: ModuleInfo[]): string {
|
|||
import '/shell.js';
|
||||
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
|
||||
|
||||
// Logged-in users: swap CTA to "Go to My Space"
|
||||
// Logged-in users: hide header demo btn, swap hero CTA to "Go to My Space"
|
||||
try {
|
||||
var raw = localStorage.getItem('encryptid_session');
|
||||
if (raw) {
|
||||
var session = JSON.parse(raw);
|
||||
var hdrBtn = document.querySelector('.rstack-header__demo-btn');
|
||||
if (hdrBtn) hdrBtn.setAttribute('data-hide', '');
|
||||
if (session?.claims?.username) {
|
||||
var username = session.claims.username.toLowerCase();
|
||||
var primary = document.getElementById('ml-primary');
|
||||
|
|
|
|||
|
|
@ -102,15 +102,22 @@ export function renderShell(opts: ShellOptions): string {
|
|||
// Provide module list to app switcher
|
||||
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
|
||||
|
||||
// ── Bare-domain "Try Demo" button visibility ──
|
||||
// On rspace.online (bare domain), the server internally rewrites to demo space,
|
||||
// but we still want the "Try Demo" button visible since it links to the explicit demo subdomain.
|
||||
// ── "Try Demo" button visibility ──
|
||||
// Hidden when logged in. When logged out, shown everywhere except demo.rspace.online
|
||||
// (bare rspace.online rewrites to demo internally but still shows the button).
|
||||
(function() {
|
||||
var host = window.location.host.split(':')[0];
|
||||
if (host === 'rspace.online' || host === 'www.rspace.online') {
|
||||
var btn = document.querySelector('.rstack-header__demo-btn');
|
||||
if (btn) btn.removeAttribute('data-hide');
|
||||
var btn = document.querySelector('.rstack-header__demo-btn');
|
||||
if (!btn) return;
|
||||
function update() {
|
||||
var loggedIn = false;
|
||||
try { loggedIn = !!localStorage.getItem('encryptid_session'); } catch(e) {}
|
||||
if (loggedIn) { btn.setAttribute('data-hide', ''); return; }
|
||||
var host = window.location.host.split(':')[0];
|
||||
if (host === 'demo.rspace.online') { btn.setAttribute('data-hide', ''); }
|
||||
else { btn.removeAttribute('data-hide'); }
|
||||
}
|
||||
update();
|
||||
document.addEventListener('auth-change', update);
|
||||
})();
|
||||
|
||||
// ── Welcome overlay (first visit to demo) ──
|
||||
|
|
@ -689,6 +696,17 @@ export function renderModuleLanding(opts: ModuleLandingOptions): string {
|
|||
<script type="module">
|
||||
import '/shell.js?v=6';
|
||||
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
|
||||
function _updateDemoBtn() {
|
||||
var btn = document.querySelector('.rstack-header__demo-btn');
|
||||
if (!btn) return;
|
||||
try {
|
||||
var raw = localStorage.getItem('encryptid_session');
|
||||
if (raw && JSON.parse(raw)?.accessToken) { btn.setAttribute('data-hide', ''); }
|
||||
else { btn.removeAttribute('data-hide'); }
|
||||
} catch(e) {}
|
||||
}
|
||||
_updateDemoBtn();
|
||||
document.addEventListener('auth-change', _updateDemoBtn);
|
||||
try {
|
||||
var raw = localStorage.getItem('encryptid_session');
|
||||
if (raw) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue