: asapien/signet

commit 253b4235cb42a8b0a9c8d1c4b4e65f6cfd89e9ed
parent ad9e63e74265c4e8a0038eb53c373f0eadec5788
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 05:55:00 +0530

PIM: Add console logging and better error messages

Improve debugging and error handling in PIM portal:
- Add console.log for fetch calls and responses
- Better error messages for common issues
- Show 'Check console (F12)' hint in error display
- Handle missing roles gracefully

This helps users diagnose Authelia setup issues and API errors.
When /pim-api/me returns 401, shows clear setup instructions.

Deploy and test:
1. Open http://localhost:8080/pim/
2. Press F12 for browser console
3. Check for detailed error messages
4. If 401: start Authelia and enable proxy in lighttpd-dev.conf

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 file changed, 13 insertions(+), 7 deletions(-)
M
pim/www/pim.js
|
20
+++++++++++++-------
diff --git a/pim/www/pim.js b/pim/www/pim.js
@@ -7,26 +7,32 @@ let attrs = {};
 
 async function boot() {
   try {
+    console.log('Fetching /pim-api/me...');
     const res = await fetch('/pim-api/me');
+    console.log('Response status:', res.status);
+    
     if (res.status === 401) {
-      document.getElementById('auth').innerHTML = '<h1>Not Authenticated</h1><p>PIM requires Authelia authentication. Start Authelia and enable the proxy in lighttpd.</p><p><code>docker run -d --name authelia -p 9091:9091 -v $(pwd)/etc/authelia.yml:/etc/authelia/authelia.yml -v $(pwd)/etc/authelia-users.yml:/etc/authelia/users.yml authelia/authelia:latest</code></p><p>Then uncomment the proxy line in test/lighttpd-dev.conf and restart the test container.</p>';
+      document.getElementById('auth').innerHTML = '<h1>Authentication Required</h1><p>Start Authelia:</p><pre>docker run -d --name authelia -p 9091:9091 -v $(pwd)/etc/authelia.yml:/etc/authelia/authelia.yml -v $(pwd)/etc/authelia-users.yml:/etc/authelia/users.yml authelia/authelia:latest</pre><p>Then uncomment proxy line in test/lighttpd-dev.conf and restart.</p>';
       return;
     }
     if (!res.ok) throw new Error('HTTP ' + res.status);
+    
     me = await res.json();
-
-    if (!me.roles.pim_admin) {
-      document.getElementById('auth').innerHTML = '<h1>Access Denied</h1><p>You are logged in as <strong>' + me.user + '</strong>. Only users with <code>pim_admin</code> role can access PIM.</p><p>Login with a user that has pim_admin role (e.g., admin/admin).</p>';
+    console.log('Authenticated as:', me.user);
+    
+    if (!me.roles || !me.roles.pim_admin) {
+      document.getElementById('auth').innerHTML = '<h1>Access Denied</h1><p>User ' + (me.user || 'unknown') + ' does not have pim_admin role. Login as admin/admin.</p>';
       return;
     }
-
+    
     document.getElementById('auth').style.display = 'none';
     document.getElementById('attrs').style.display = 'block';
     document.getElementById('whoami').textContent = me.user + ' ยท pim_admin';
-
+    
     await loadOrgs();
   } catch (e) {
-    document.getElementById('auth').innerHTML = '<h1>Error</h1><p>' + e.message + '</p>';
+    console.error(e);
+    document.getElementById('auth').innerHTML = '<h1>Error</h1><p>' + e.message + '</p><p>Check console (F12) for details.</p>';
   }
 }