Initial commit from ux_aura_assistant

This commit is contained in:
DIVYANSH-675
2026-03-25 01:21:46 +05:30
commit cb404432ee
48 changed files with 2530 additions and 0 deletions

7
hooks/useAuth.ts Normal file
View File

@@ -0,0 +1,7 @@
import { useAuthContext } from '../contexts/AuthContext';
// Export as useAuth to maintain backward compatibility
export const useAuth = () => {
return useAuthContext();
};

62
hooks/useAuthSession.ts Normal file
View File

@@ -0,0 +1,62 @@
import { useState, useEffect } from 'react';
import { User, Role, Permission } from '../types';
import * as appBuilderService from '../services/appBuilderService';
export const useAuthSession = () => {
const [authState, setAuthState] = useState<'checking' | 'authorized' | 'unauthorized'>('checking');
const [user, setUser] = useState<User | null>(null);
const [roles, setRoles] = useState<Role[]>([]);
const [permissions, setPermissions] = useState<Permission[]>([]);
useEffect(() => {
const checkAuth = async () => {
const isStudio = window.location.href.includes('.goog');
const isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
// Configure Gemini API Key globally for compatibility
(window as any).GEMINI_API_KEY = isStudio
? ((window as any).process?.env?.API_KEY || 'NOTFOUND')
: 'NOT_SET';
if (isLocal) {
setUser({ name: 'Local Dev User', company_name: 'HumanizeIQ', uid: 'local-dev-uid' });
setAuthState('authorized');
setRoles(['Admin']);
setPermissions(['all:access']);
return;
}
const authUrl = isGoogDomain ? 'https://www.playtest.humanizeiq.ai/auth/ai_studio' : '/auth/ai_studio';
try {
const fetchOptions: RequestInit = { credentials: 'include' };
const response = await fetch(authUrl, fetchOptions);
if (response.status === 200) {
const result = await response.json();
if (result.data?.firstname) {
setUser({
name: `${result.data.firstname} ${result.data.lastname}`,
company_name: result.data.company_name,
auth_cookie: result.data.auth_cookie_base64,
uid: result.data.uid
});
setAuthState('authorized');
const rbacData = await appBuilderService.getMyRbacDetails().catch(() => ({ roles: [], permissions: [] }));
setRoles(rbacData.roles);
setPermissions(rbacData.permissions);
} else {
setAuthState('unauthorized');
}
} else {
setAuthState('unauthorized');
}
} catch (error) {
setAuthState('unauthorized');
}
};
checkAuth();
}, []);
return { authState, user, roles, permissions };
};

31
hooks/useLocalStorage.ts Normal file
View File

@@ -0,0 +1,31 @@
// FIX: Import React to make the 'React' namespace available for type annotations.
import React, { useState, useEffect } from 'react';
export function useLocalStorage<T,>(key: string, initialValue: T): [T, React.Dispatch<React.SetStateAction<T>>] {
const [storedValue, setStoredValue] = useState<T>(() => {
if (typeof window === 'undefined') {
return initialValue;
}
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
console.error(error);
return initialValue;
}
});
useEffect(() => {
try {
const valueToStore =
typeof storedValue === 'function'
? storedValue(storedValue)
: storedValue;
window.localStorage.setItem(key, JSON.stringify(valueToStore));
} catch (error) {
console.error(error);
}
}, [key, storedValue]);
return [storedValue, setStoredValue];
}