feat: add token-based auth UI in dashboard
This commit is contained in:
parent
f17863f28d
commit
1ca4f04bcc
1 changed files with 24 additions and 2 deletions
|
|
@ -1,6 +1,28 @@
|
|||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
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 [tasks, setTasks] = useState([]);
|
||||
const [selectedTask, setSelectedTask] = useState(null);
|
||||
|
|
@ -29,7 +51,7 @@ const App = () => {
|
|||
const [chatMessages, setChatMessages] = useState([]);
|
||||
const [chatInput, setChatInput] = useState('');
|
||||
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 [chatModel, setChatModel] = useState('');
|
||||
const chatEndRef = useRef(null);
|
||||
|
|
@ -126,7 +148,7 @@ const App = () => {
|
|||
|
||||
const startNewChat = () => {
|
||||
setChatMessages([]);
|
||||
const newId = crypto.randomUUID ? crypto.randomUUID() : Date.now().toString();
|
||||
const newId = generateUUID();
|
||||
setChatSessionId(newId);
|
||||
if (wsRef.current) { wsRef.current.close(); wsRef.current = null; }
|
||||
};
|
||||
|
|
|
|||
Reference in a new issue