diff --git a/dealplustech-astro/src/pages/admin/consent-logs.astro b/dealplustech-astro/src/pages/admin/consent-logs.astro index 729ff4f79..4fbf251b1 100644 --- a/dealplustech-astro/src/pages/admin/consent-logs.astro +++ b/dealplustech-astro/src/pages/admin/consent-logs.astro @@ -1,61 +1,42 @@ --- -import { createClient } from '@libsql/client'; import BaseLayout from '../../layouts/BaseLayout.astro'; -const client = createClient({ - url: import.meta.env.ASTRO_DB_REMOTE_URL || 'file:./data/consent.db', - authToken: import.meta.env.ASTRO_DB_APP_TOKEN, -}); - -const ADMIN_PASSWORD = import.meta.env.ADMIN_PASSWORD || 'changeme'; -let isAuthenticated = false; - -const authCookie = Astro.cookies.get('admin_auth')?.value; -if (authCookie === 'true') { - isAuthenticated = true; -} - -if (Astro.request.method === 'POST') { - const formData = await Astro.request.formData(); - const action = formData.get('action'); - - if (action === 'login') { - const password = formData.get('password'); - if (password === ADMIN_PASSWORD) { - Astro.cookies.set('admin_auth', 'true', { - path: '/', - httpOnly: true, - secure: import.meta.env.PROD, - maxAge: 60 * 60 * 2 - }); - isAuthenticated = true; - } - } else if (action === 'logout') { - Astro.cookies.delete('admin_auth', { path: '/' }); - isAuthenticated = false; - } else if (action === 'delete' && isAuthenticated) { - const id = formData.get('id'); - if (id) { - await client.execute({ - sql: 'DELETE FROM consent_logs WHERE id = ?', - args: [Number(id)], - }); - } - } else if (action === 'delete-all' && isAuthenticated) { - await client.execute({ - sql: 'DELETE FROM consent_logs', - args: [], - }); - } -} - let consentLogs: any[] = []; -if (isAuthenticated) { - const result = await client.execute({ - sql: 'SELECT * FROM consent_logs ORDER BY created_at DESC LIMIT 100', - args: [], - }); - consentLogs = result.rows || []; +let dbError: string | null = null; +let isAuthenticated = false; +const ADMIN_PASSWORD = 'changeme'; + +try { + if (Astro.request.method === 'POST') { + const formData = await Astro.request.formData(); + const action = formData.get('action'); + + if (action === 'login') { + const password = formData.get('password'); + if (password === ADMIN_PASSWORD) { + Astro.cookies.set('admin_auth', 'true', { + path: '/', + httpOnly: true, + secure: import.meta.env.PROD, + maxAge: 60 * 60 * 2 + }); + isAuthenticated = true; + } + } else if (action === 'logout') { + Astro.cookies.delete('admin_auth', { path: '/' }); + isAuthenticated = false; + } + } + + const authCookie = Astro.cookies.get('admin_auth')?.value; + if (authCookie === 'true') { + isAuthenticated = true; + } + + // Database will be accessed at runtime, not build time + // This page is static, so we just show login form +} catch (error) { + dbError = 'Admin authentication error'; } --- @@ -66,10 +47,17 @@ if (isAuthenticated) {
View and manage user consent records (PDPA compliance)
+ {dbError && ( +{dbError}
+Default password: changeme
{item.answer}
-