diff --git a/.env.example b/.env.example index 73f7ea9..ce55860 100644 --- a/.env.example +++ b/.env.example @@ -32,8 +32,8 @@ AUTHENTICATION_NECESSARY_CONTRIBUTIONS=false AUTHENTICATION_NECESSARY_AI=false AUTHENTICATION_NECESSARY_GATEDCONTENT=true -# OIDC Provider Configuration -OIDC_ENDPOINT=https://your-nextcloud.com/index.php/apps/oidc +# OIDC Provider Configuration - Server appends endpoint (e.g. auth/callback) automatically +OIDC_ENDPOINT=https://cloud.cc24.dev/index.php OIDC_CLIENT_ID=your-client-id OIDC_CLIENT_SECRET=your-client-secret diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index 6330d69..bfd51bf 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -229,6 +229,12 @@ const { title, description = 'ForensicPathways - A comprehensive directory of di authRequired: data.aiAuthRequired, expires: data.expires }; + case 'gatedcontent': // ADD THIS CASE + return { + authenticated: data.gatedContentAuthenticated, + authRequired: data.gatedContentAuthRequired, + expires: data.expires + }; default: return { authenticated: data.authenticated, diff --git a/src/pages/api/auth/process.ts b/src/pages/api/auth/process.ts index e7abed9..2afa73f 100644 --- a/src/pages/api/auth/process.ts +++ b/src/pages/api/auth/process.ts @@ -44,16 +44,12 @@ export const POST: APIRoute = async ({ request }) => { }); const responseHeaders = new Headers(); - responseHeaders.set('Content-Type', 'application/json'); - + responseHeaders.set('Location', stateVerification.stateData.returnTo); responseHeaders.append('Set-Cookie', sessionResult.sessionCookie); responseHeaders.append('Set-Cookie', sessionResult.clearStateCookie); - - return new Response(JSON.stringify({ - success: true, - redirectTo: stateVerification.stateData.returnTo - }), { - status: 200, + + return new Response(null, { + status: 302, headers: responseHeaders }); diff --git a/src/pages/knowledgebase.astro b/src/pages/knowledgebase.astro index 0889c8d..66284a0 100644 --- a/src/pages/knowledgebase.astro +++ b/src/pages/knowledgebase.astro @@ -174,7 +174,9 @@ const publicCount = knowledgebaseEntries.length - gatedCount;
- + diff --git a/src/pages/knowledgebase/[slug].astro b/src/pages/knowledgebase/[slug].astro index 492bed7..8cdb449 100644 --- a/src/pages/knowledgebase/[slug].astro +++ b/src/pages/knowledgebase/[slug].astro @@ -68,6 +68,19 @@ const currentUrl = Astro.url.href; console.log('[GATED CONTENT] Checking client-side auth for: ' + articleTitle); + // Hide content immediately while checking auth + const contentArea = document.querySelector('.article-content'); + const sidebar = document.querySelector('.article-sidebar'); + + + if (contentArea) { + contentArea.style.display = 'none'; + } + // DON'T hide the sidebar container - just prevent TOC generation + //if (sidebar) { + //sidebar.innerHTML = ''; // Clear any content instead of hiding + //} + try { const response = await fetch('/api/auth/status'); const authStatus = await response.json(); @@ -78,44 +91,64 @@ const currentUrl = Astro.url.href; console.log('[GATED CONTENT] Auth status - Required: ' + authRequired + ', Authenticated: ' + isAuthenticated); if (authRequired && !isAuthenticated) { - console.log('[GATED CONTENT] Redirecting for authentication: ' + articleTitle); + console.log('[GATED CONTENT] Access denied - showing auth required message: ' + articleTitle); - // Show loading message briefly - const contentArea = document.querySelector('.article-content'); + // Show authentication required message (no auto-redirect) if (contentArea) { + const loginUrl = '/api/auth/login?returnTo=' + encodeURIComponent(window.location.href); contentArea.innerHTML = [ - '
', - '
🔒
', - '

Authentifizierung erforderlich

', - '

Sie werden zur Anmeldung weitergeleitet...

', + '
' ].join(''); + contentArea.style.display = 'block'; } - - // Redirect to login after brief delay - setTimeout(() => { - const currentUrl = encodeURIComponent(window.location.href); - window.location.href = '/api/auth/login?returnTo=' + currentUrl; - }, 1000); } else { console.log('[GATED CONTENT] Access granted for: ' + articleTitle); + // Show content for authenticated users + if (contentArea) { + contentArea.style.display = 'block'; + } + // Let TOC generate normally for authenticated users + setTimeout(() => { + if (typeof generateTOCContent === 'function') { + generateTOCContent(); + } + }, 100); } } catch (error) { console.error('[GATED CONTENT] Auth check failed:', error); // On error, show auth required message - if (requiresAuth) { - const contentArea = document.querySelector('.article-content'); - if (contentArea) { - const loginUrl = '/api/auth/login?returnTo=' + encodeURIComponent(window.location.href); - contentArea.innerHTML = [ - '
', - '
⚠️
', - '

Authentifizierungsfehler

', - '

Bitte versuchen Sie es später erneut oder melden Sie sich an.

', + if (requiresAuth && contentArea) { + const loginUrl = '/api/auth/login?returnTo=' + encodeURIComponent(window.location.href); + contentArea.innerHTML = [ + '
', + '
⚠️
', + '

Authentifizierungsfehler

', + '

Es gab ein Problem bei der Überprüfung Ihrer Berechtigung. Bitte versuchen Sie es erneut.

', + '
', 'Anmelden', - '
' - ].join(''); - } + '', + '
', + '
' + ].join(''); + contentArea.style.display = 'block'; } } }); @@ -245,7 +278,7 @@ const currentUrl = Astro.url.href;
-
+
@@ -337,7 +370,7 @@ const currentUrl = Astro.url.href;
-