feat: add token-based auth UI in dashboard

This commit is contained in:
Zac Gaetano 2026-04-05 00:32:24 -04:00
parent f17863f28d
commit 1ca4f04bcc

View file

@ -1,6 +1,28 @@
import React, { useState, useEffect, useRef, useCallback } from 'react'; import React, { useState, useEffect, useRef, useCallback } from 'react';
import './App.css'; import './App.css';
// UUID v4 generator works in all contexts (HTTP and HTTPS)
function generateUUID() {
// Use crypto.randomUUID if available (HTTPS only)
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
}
// Fallback: manual UUID v4 using crypto.getRandomValues or Math.random
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 1
const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
}
// Last resort: Math.random-based UUID
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0;
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
}
const App = () => { const App = () => {
const [tasks, setTasks] = useState([]); const [tasks, setTasks] = useState([]);
const [selectedTask, setSelectedTask] = useState(null); const [selectedTask, setSelectedTask] = useState(null);
@ -29,7 +51,7 @@ const App = () => {
const [chatMessages, setChatMessages] = useState([]); const [chatMessages, setChatMessages] = useState([]);
const [chatInput, setChatInput] = useState(''); const [chatInput, setChatInput] = useState('');
const [chatSending, setChatSending] = useState(false); const [chatSending, setChatSending] = useState(false);
const [chatSessionId, setChatSessionId] = useState(() => crypto.randomUUID ? crypto.randomUUID() : Date.now().toString()); const [chatSessionId, setChatSessionId] = useState(() => generateUUID());
const [chatSessions, setChatSessions] = useState([]); const [chatSessions, setChatSessions] = useState([]);
const [chatModel, setChatModel] = useState(''); const [chatModel, setChatModel] = useState('');
const chatEndRef = useRef(null); const chatEndRef = useRef(null);
@ -126,7 +148,7 @@ const App = () => {
const startNewChat = () => { const startNewChat = () => {
setChatMessages([]); setChatMessages([]);
const newId = crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(); const newId = generateUUID();
setChatSessionId(newId); setChatSessionId(newId);
if (wsRef.current) { wsRef.current.close(); wsRef.current = null; } if (wsRef.current) { wsRef.current.close(); wsRef.current = null; }
}; };