mirror of
https://codeberg.org/likwid/likwid.git
synced 2026-02-10 05:23:09 +00:00
demo: preserve next param in gated flow
This commit is contained in:
parent
8d199d5eab
commit
c00814156d
2 changed files with 23 additions and 5 deletions
|
|
@ -38,7 +38,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||
}
|
||||
|
||||
if (path === '/setup' || path === '/register') {
|
||||
return context.redirect('/demo');
|
||||
return context.redirect(`/demo?next=${encodeURIComponent(path + url.search)}`);
|
||||
}
|
||||
|
||||
const isProtected =
|
||||
|
|
@ -58,7 +58,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||
|
||||
const unlocked = context.cookies.get(DEMO_COOKIE)?.value === '1';
|
||||
if (!unlocked) {
|
||||
return context.redirect('/demo');
|
||||
return context.redirect(`/demo?next=${encodeURIComponent(path + url.search)}`);
|
||||
}
|
||||
|
||||
return next();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
export const prerender = false;
|
||||
import PublicLayout from '../layouts/PublicLayout.astro';
|
||||
import { API_BASE } from '../lib/api';
|
||||
|
||||
const nextParamRaw = Astro.url.searchParams.get('next') || '';
|
||||
const nextParam = nextParamRaw.startsWith('/') ? nextParamRaw : '';
|
||||
const nextQuery = nextParam ? `&next=${encodeURIComponent(nextParam)}` : '';
|
||||
---
|
||||
|
||||
<PublicLayout title="Demo" description="Explore Likwid's governance features with a live demo instance featuring pre-populated communities and real governance history.">
|
||||
|
|
@ -15,6 +19,15 @@ import { API_BASE } from '../lib/api';
|
|||
</p>
|
||||
</header>
|
||||
|
||||
${nextParam ? `
|
||||
<div class="demo-status-banner" id="demo-continue">
|
||||
<p>
|
||||
You were trying to open <code>${nextParam.replace(/</g, '<')}</code>.
|
||||
Enter the demo to continue.
|
||||
</p>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<section class="demo-intro">
|
||||
<div class="intro-content">
|
||||
<h2>Why a Demo Instance?</h2>
|
||||
|
|
@ -200,8 +213,8 @@ import { API_BASE } from '../lib/api';
|
|||
Use demo accounts to participate.
|
||||
</p>
|
||||
<div class="cta-buttons">
|
||||
<a href="/demo?enter=1&next=/communities" class="btn-primary btn-large">Enter the Demo</a>
|
||||
<a href="/demo?enter=1&next=/login" class="btn-secondary">Sign In with Demo Account</a>
|
||||
<a href={`/demo?enter=1${nextQuery || '&next=%2Fcommunities'}`} class="btn-primary btn-large">Enter the Demo</a>
|
||||
<a href={`/demo?enter=1${nextQuery || '&next=%2Flogin'}`} class="btn-secondary">Continue</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
|
@ -738,6 +751,10 @@ import { API_BASE } from '../lib/api';
|
|||
</style>
|
||||
|
||||
<script define:vars={{ API_BASE }}>
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const nextParam = currentUrl.searchParams.get('next') || '';
|
||||
const nextPath = nextParam && nextParam.startsWith('/') ? nextParam : '';
|
||||
|
||||
async function loadDemoData() {
|
||||
try {
|
||||
// Fetch demo status
|
||||
|
|
@ -814,7 +831,8 @@ import { API_BASE } from '../lib/api';
|
|||
const result = await response.json();
|
||||
localStorage.setItem('token', result.token);
|
||||
localStorage.setItem('user', JSON.stringify(result.user));
|
||||
window.location.href = '/demo?enter=1&next=/communities';
|
||||
const nextTarget = nextPath || '/communities';
|
||||
window.location.href = '/demo?enter=1&next=' + encodeURIComponent(nextTarget);
|
||||
} catch (error) {
|
||||
console.error('Demo login failed:', error);
|
||||
if (btn) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue