Skip to content

Commit e35c475

Browse files
committed
Add PII sanitization and CSS theming with design tokens
1 parent b6fbd4f commit e35c475

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

public/js/components/pf-dialog.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PfDialog extends HTMLElement {
6868
<style>
6969
:host {
7070
display: block;
71-
font-family: Arial, sans-serif;
71+
font-family: var(--font-family, 'SpaceMono', monospace);
7272
}
7373
7474
.dialog-backdrop {
@@ -77,7 +77,7 @@ class PfDialog extends HTMLElement {
7777
left: 0;
7878
width: 100%;
7979
height: 100%;
80-
background-color: rgba(0, 0, 0, 0.5);
80+
background-color: var(--overlay-color, rgba(0, 0, 0, 0.5));
8181
display: flex;
8282
align-items: center;
8383
justify-content: center;
@@ -93,9 +93,9 @@ class PfDialog extends HTMLElement {
9393
}
9494
9595
.dialog {
96-
background-color: white;
97-
border-radius: 8px;
98-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
96+
background-color: var(--card-background, white);
97+
border-radius: var(--border-radius-lg, 8px);
98+
box-shadow: var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.15));
9999
width: 90%;
100100
max-width: 450px;
101101
max-height: 90vh;
@@ -111,32 +111,32 @@ class PfDialog extends HTMLElement {
111111
112112
.dialog-header {
113113
padding: 16px 20px;
114-
border-bottom: 1px solid #e5e7eb;
114+
border-bottom: 1px solid var(--border-color, #e5e7eb);
115115
}
116116
117117
.dialog-title {
118118
margin: 0;
119119
font-size: 18px;
120120
font-weight: 600;
121-
color: #111827;
121+
color: var(--text-primary, #111827);
122122
}
123123
124124
.dialog-body {
125125
padding: 20px;
126-
color: #4b5563;
126+
color: var(--text-secondary, #4b5563);
127127
}
128128
129129
.dialog-footer {
130130
padding: 16px 20px;
131-
border-top: 1px solid #e5e7eb;
131+
border-top: 1px solid var(--border-color, #e5e7eb);
132132
display: flex;
133133
justify-content: flex-end;
134134
gap: 12px;
135135
}
136136
137137
.dialog-button {
138138
padding: 8px 16px;
139-
border-radius: 6px;
139+
border-radius: var(--border-radius-md, 6px);
140140
font-size: 14px;
141141
font-weight: 500;
142142
cursor: pointer;
@@ -145,21 +145,21 @@ class PfDialog extends HTMLElement {
145145
}
146146
147147
.cancel-button {
148-
background-color: #f3f4f6;
149-
color: #4b5563;
148+
background-color: var(--surface-variant, #f3f4f6);
149+
color: var(--text-secondary, #4b5563);
150150
}
151151
152152
.cancel-button:hover {
153-
background-color: #e5e7eb;
153+
background-color: var(--divider-color, #e5e7eb);
154154
}
155155
156156
.confirm-button {
157-
background-color: #2563eb;
158-
color: white;
157+
background-color: var(--primary-color, #e02337);
158+
color: var(--text-on-primary, white);
159159
}
160160
161161
.confirm-button:hover {
162-
background-color: #1d4ed8;
162+
background-color: var(--primary-dark, #c01d2f);
163163
}
164164
</style>
165165

public/js/components/pf-header.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,31 @@ class PfHeader extends HTMLElement {
509509
}
510510
}
511511

512+
/**
513+
* Store user data in localStorage without PII
514+
* @param {Object} userData - User data from server
515+
*/
516+
storeUserData(userData) {
517+
if (!userData) return;
518+
519+
// Create a sanitized user object without PII
520+
const sanitizedUser = {
521+
id: userData.id,
522+
username: userData.username || userData.email?.split('@')[0] || 'User',
523+
role: userData.role || 'user',
524+
created_at: userData.created_at,
525+
updated_at: userData.updated_at
526+
};
527+
528+
// Store the sanitized user object in localStorage
529+
try {
530+
localStorage.setItem('user', JSON.stringify(sanitizedUser));
531+
console.log('User data stored in localStorage without PII');
532+
} catch (error) {
533+
console.error('Error storing user data in localStorage:', error);
534+
}
535+
}
536+
512537
updateNavbar() {
513538
// Check for JWT token instead of API key
514539
const jwtToken = localStorage.getItem('jwt_token');
@@ -519,6 +544,9 @@ class PfHeader extends HTMLElement {
519544
const userJson = localStorage.getItem('user');
520545
if (userJson) {
521546
userObject = JSON.parse(userJson);
547+
} else if (jwtToken) {
548+
// If we have a JWT but no user object, try to get user info from the auth status endpoint
549+
this.fetchUserData(jwtToken);
522550
}
523551
} catch (error) {
524552
console.error('Error parsing user object from localStorage:', error);
@@ -761,6 +789,31 @@ class PfHeader extends HTMLElement {
761789
}
762790
}
763791

792+
/**
793+
* Fetch user data from the auth status endpoint
794+
* @param {string} jwtToken - JWT token
795+
*/
796+
async fetchUserData(jwtToken) {
797+
try {
798+
const response = await fetch('/api/1/auth/status', {
799+
method: 'GET',
800+
headers: {
801+
'Authorization': `Bearer ${jwtToken}`
802+
}
803+
});
804+
805+
if (response.ok) {
806+
const data = await response.json();
807+
if (data.authenticated && data.auth_user) {
808+
// Store user data without PII
809+
this.storeUserData(data.auth_user);
810+
}
811+
}
812+
} catch (error) {
813+
console.error('Error fetching user data:', error);
814+
}
815+
}
816+
764817
logout() {
765818
// Clear JWT token and user data
766819
localStorage.removeItem('jwt_token');

public/js/page-initializers.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ export async function initLoginPage() {
117117
// User has an active subscription
118118
localStorage.setItem('subscription_data', JSON.stringify(subscriptionStatus));
119119

120-
// Create and store a publicly accessible user object
120+
// Create and store a sanitized user object without PII
121121
const userObject = {
122-
email: email,
123-
username: email,
122+
username: email.split('@')[0], // Extract username from email
124123
subscription: {
125124
plan: subscriptionStatus.plan || 'monthly',
126125
status: subscriptionStatus.status || 'active',
@@ -131,10 +130,9 @@ export async function initLoginPage() {
131130
localStorage.setItem('user', JSON.stringify(userObject));
132131
} else {
133132
console.log('No subscription data available or user has no active subscription');
134-
// Create a basic user object without subscription data
133+
// Create a basic sanitized user object without PII
135134
const userObject = {
136-
email: email,
137-
username: email,
135+
username: email.split('@')[0], // Extract username from email
138136
subscription: {
139137
status: 'unknown'
140138
},
@@ -290,10 +288,9 @@ export function initRegisterPage() {
290288
localStorage.setItem('username', email);
291289
localStorage.setItem('subscription_data', JSON.stringify(subscriptionData));
292290

293-
// Create and store a publicly accessible user object
291+
// Create and store a sanitized user object without PII
294292
const userObject = {
295-
email: email,
296-
username: email,
293+
username: email.split('@')[0], // Extract username from email
297294
subscription: {
298295
plan: subscriptionData.subscription?.plan || selectedPlan,
299296
status: 'pending',

0 commit comments

Comments
 (0)