Skip to content

Commit e6dc024

Browse files
committed
Merge branch 'master' of github.com:profullstack/generate-pdf-api
2 parents b95d26d + d879986 commit e6dc024

File tree

14 files changed

+647
-37
lines changed

14 files changed

+647
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,4 @@ CREATE TABLE IF NOT EXISTS user_preferences (
316316
CREATE INDEX IF NOT EXISTS idx_user_preferences_user_id ON user_preferences(user_id);
317317
```
318318

319-
For more information on Supabase migrations, see the [Supabase CLI documentation](https://supabase.com/docs/reference/cli/supabase-db-push).
319+
For more information on Supabase migrations, see the [Supabase CLI documentation](https://supabase.com/docs/reference/cli/supabase-db-push).

public/js/components/pf-header.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class PfHeader extends HTMLElement {
284284
</div>
285285
286286
<div class="nav-links">
287+
<a href="/dashboard" class="nav-link" id="dashboard-link">Dashboard</a>
287288
<a href="/api-docs" class="nav-link" id="api-docs-link">API Docs</a>
288289
<a href="/api-keys" class="nav-link" id="api-keys-link">API Keys</a>
289290
<a href="/login" class="nav-link login-link" id="login-link">Login</a>
@@ -303,6 +304,7 @@ class PfHeader extends HTMLElement {
303304
304305
<!-- Mobile menu container -->
305306
<div class="mobile-menu">
307+
<a href="/dashboard" class="nav-link" id="mobile-dashboard-link">Dashboard</a>
306308
<a href="/api-docs" class="nav-link" id="mobile-api-docs-link">API Docs</a>
307309
<a href="/api-keys" class="nav-link" id="mobile-api-keys-link">API Keys</a>
308310
<a href="/login" class="nav-link login-link" id="mobile-login-link">Login</a>
@@ -390,7 +392,9 @@ class PfHeader extends HTMLElement {
390392
});
391393

392394
// Add active class to the current link
393-
if (currentPath.startsWith('/api-docs')) {
395+
if (currentPath.startsWith('/dashboard')) {
396+
this.shadowRoot.querySelector('#dashboard-link')?.classList.add('active');
397+
} else if (currentPath.startsWith('/api-docs')) {
394398
this.shadowRoot.querySelector('#api-docs-link')?.classList.add('active');
395399
} else if (currentPath.startsWith('/api-keys')) {
396400
this.shadowRoot.querySelector('#api-keys-link')?.classList.add('active');
@@ -649,7 +653,7 @@ class PfHeader extends HTMLElement {
649653

650654
// Redirect to home page if on a protected page
651655
const currentPath = window.location.pathname;
652-
const protectedPages = ['/api-keys', '/settings'];
656+
const protectedPages = ['/api-keys', '/settings', '/dashboard'];
653657

654658
if (protectedPages.includes(currentPath)) {
655659
if (window.router) {

public/js/main.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function initRouter() {
4646
view: () => loadPage('/views/register.html'),
4747
afterRender: () => initRegisterPage()
4848
},
49+
'/dashboard': {
50+
view: () => loadPage('/views/dashboard.html'),
51+
afterRender: () => checkAuthAndInitPage('dashboard')
52+
},
4953
'/api-docs': {
5054
view: () => loadPage('/views/api-docs.html')
5155
},
@@ -344,6 +348,29 @@ function initRegisterPage() {
344348

345349
// Function removed - no more mock data
346350

351+
/**
352+
* Check if user is authenticated and initialize page
353+
* @param {string} pageType - Type of page to initialize
354+
*/
355+
function checkAuthAndInitPage(pageType) {
356+
// Check if user is logged in
357+
const apiKey = localStorage.getItem('api_key');
358+
if (!apiKey) {
359+
// Redirect to login page
360+
window.router.navigate('/login');
361+
return;
362+
}
363+
364+
// Initialize specific page if needed
365+
switch (pageType) {
366+
case 'dashboard':
367+
// Dashboard initialization is handled by the page's own script
368+
break;
369+
default:
370+
break;
371+
}
372+
}
373+
347374
/**
348375
* Initialize API keys page
349376
*/
@@ -495,5 +522,6 @@ function initSubscriptionPage() {
495522
// Expose functions globally
496523
window.app = {
497524
initApp,
498-
initRouter
525+
initRouter,
526+
checkAuthAndInitPage
499527
};

0 commit comments

Comments
 (0)