Files
paskia/examples/index.html
T
LeoVasanko 0ca4e07e23 Dev server: serve paskia-js module, rework examples page
The Vite dev server now maps /paskia-js/ to the local paskia-js build
(the examples page's module import has 404'd since it was introduced,
leaving all buttons dead). Navigation actions on the examples page are
now plain same-window links so the flows' back navigation returns to
the page; added a Profile Summary button exercising profile().
2026-09-17 19:17:00 +00:00

113 lines
4.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paskia - Dev Mode</title>
<style>
:root {
color-scheme: light dark; /* Automatic themes by browser */
}
.section a, .section button {
display: inline-block;
padding: 0.2em 0.6em;
margin: 1px 4px 1px 0;
border: none;
background: #ccc8;
color: inherit;
font: inherit;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>🔐 Paskia - Development Server</h1>
<p class="subtitle">The following features are available after you have registered your Admin account and logged in. You should also use the Admin Site to create non-privileged users to see the Forbidden dialog caused by missing permissions.</p>
</header>
<div class="content">
<div class="section">
<h2>Management Site</h2>
<a href="/auth/">👤 User Profile</a>
<a href="/auth/admin/">⚙️ Admin Panel</a>
</div>
<div class="section">
<h2>API Mode (not leaving the page)</h2>
<p>For SPAs and fetch() calls - shows auth in an iframe overlay:</p>
<button onclick="apiCall('/auth/api/user-info', 'GET')">📋 Get User Info</button>
<button onclick="apiCall('/auth/api/forward?max_age=10s')">🔄 Reauth (max_age=10s)</button>
<button onclick="apiCall('/auth/api/forward?perm=auth:admin')">🛡️ Admin Only</button>
<button onclick="profileDemo()">👤 Profile Summary</button>
<button onclick="logout()">🚪 Logout</button>
</div>
<div class="section">
<h2>Browser Mode (full page)</h2>
<p>Block access to otherwise open site - intended for forward-auth mechanism (Caddy, Nginx). If not authenticated, you'll see the login page; after auth, a 204 response (blank page = success). Back returns here:</p>
<a href="/auth/api/forward">🔐 Basic Auth</a>
<a href="/auth/api/forward?max_age=10s">🔄 Reauth (max_age=10s)</a>
<a href="/auth/api/forward?perm=auth:admin">🛡️ Admin Only</a>
</div>
<pre id="output">Click a button to test...</pre>
</div>
</div>
<script type="module">
import { apiFetch, apiJson, AuthCancelledError, profile } from '/paskia-js/dist/paskia.js'
const output = document.getElementById('output');
function log(msg) {
output.textContent = msg;
}
// Make an API call using paskia module (handles 401/403 automatically)
window.apiCall = async function(url, method = 'GET') {
log(`${method} ${url}...`);
try {
const response = await apiFetch(url, { method });
// Forward endpoint returns 204 on success
if (response.status === 204) {
log('✓ Success (204 No Content)');
return;
}
if (!response.ok) {
log(`Error: ${response.status} ${response.statusText}`);
return;
}
const data = await response.json();
log('✓ Response:\n' + JSON.stringify(data, null, 2));
} catch (e) {
if (e instanceof AuthCancelledError) {
log('Authentication cancelled');
} else {
log(`Error: ${e.message}`);
}
}
}
window.logout = async function() {
await fetch('/auth/api/logout', { method: 'POST' });
log('Logged out');
}
// Profile dialog: resolves 'logout' if the user signed out inside the
// frame, 'back' if closed without action.
window.profileDemo = async function() {
log('Opening profile dialog...');
const result = await profile();
log(result === 'logout' ? 'Logged out inside the profile dialog' : 'Profile dialog closed (Back)');
}
</script>
</body>
</html>