Fix jwt-token

This commit is contained in:
2025-09-23 12:25:15 +02:00
parent b6509b1d67
commit 4e29272f7e

View File

@@ -372,7 +372,11 @@ const Alerts = () => {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{(alertRules || []).map((rule) => ( {(alertRules || []).map((rule) => {
// DEBUG: Aggressive debugging for this specific rule
console.log('🔍 Rendering rule:', rule.id, 'alert_channels:', rule.alert_channels, 'type:', typeof rule.alert_channels);
return (
<tr key={rule.id} className="hover:bg-gray-50"> <tr key={rule.id} className="hover:bg-gray-50">
<td> <td>
<div> <div>
@@ -403,40 +407,54 @@ const Alerts = () => {
<td> <td>
<div className="flex space-x-1"> <div className="flex space-x-1">
{(() => { {(() => {
try {
// Normalize alert_channels - ensure it's always an array // Normalize alert_channels - ensure it's always an array
let alertChannels = rule.alert_channels || []; let alertChannels = rule.alert_channels || [];
// DEBUG: Add debugging to catch object rendering // DEBUG: Add debugging to catch object rendering
if (typeof alertChannels === 'object' && alertChannels !== null) { console.log('🔍 Processing alert_channels for rule', rule.id, ':', alertChannels, 'type:', typeof alertChannels);
const hasKeys = Object.keys(alertChannels).some(key => ['sms', 'webhook', 'email'].includes(key));
if (hasKeys) { // Convert object to array if needed
console.log('DEBUG: Found problematic alert_channels object:', alertChannels, 'for rule:', rule.id); if (typeof alertChannels === 'object' && alertChannels !== null && !Array.isArray(alertChannels)) {
} console.log('🔧 Converting object to array:', alertChannels);
alertChannels = Object.keys(alertChannels).filter(key => alertChannels[key] === true);
console.log('🔧 Converted to array:', alertChannels);
} }
if (typeof alertChannels === 'object' && !Array.isArray(alertChannels)) { // Ensure it's an array
// Convert object like {sms: true, webhook: false, email: true} to array
alertChannels = Object.keys(alertChannels).filter(key => alertChannels[key]);
}
if (!Array.isArray(alertChannels)) { if (!Array.isArray(alertChannels)) {
alertChannels = []; // fallback to empty array console.warn('⚠️ alert_channels is not an array, setting to empty array:', alertChannels);
alertChannels = [];
} }
// DEBUG: Ensure we're only rendering strings // Validate all elements are strings
return alertChannels.map((channel, index) => { const validChannels = alertChannels.filter(channel => {
if (typeof channel !== 'string') { const isString = typeof channel === 'string';
console.error('DEBUG: Non-string channel detected:', channel, typeof channel); if (!isString) {
return null; console.error('❌ Non-string channel detected:', channel, typeof channel);
} }
return ( return isString;
});
console.log('✅ Final channels to render:', validChannels);
// Render the channels
const elements = validChannels.map((channel, index) => (
<span <span
key={index} key={index}
className="px-2 py-1 bg-blue-100 text-blue-800 rounded text-xs" className="px-2 py-1 bg-blue-100 text-blue-800 rounded text-xs"
> >
{channel} {channel}
</span> </span>
); ));
}).filter(Boolean);
console.log('✅ Rendered elements:', elements);
return elements;
} catch (error) {
console.error('💥 Error in alert_channels rendering:', error);
return <span className="text-red-500 text-xs">Error rendering channels</span>;
}
})()} })()}
</div> </div>
</td> </td>
@@ -512,7 +530,8 @@ const Alerts = () => {
</div> </div>
</td> </td>
</tr> </tr>
))} );
})}
</tbody> </tbody>
</table> </table>
</div> </div>