feat: update source files, Dockerfile, vite config and service worker
This commit is contained in:
@@ -8,6 +8,9 @@ import { DatabaseNameService } from '../services/graph/databaseNameService';
|
||||
import { provisionUser } from '../services/provisioningService';
|
||||
import { storageService, StorageKeys } from '../services/auth/localStorageService';
|
||||
|
||||
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
|
||||
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
|
||||
|
||||
export interface UserContextType {
|
||||
user: CCUser | null;
|
||||
loading: boolean;
|
||||
@@ -29,9 +32,9 @@ export const UserContext = createContext<UserContextType>({
|
||||
preferences: {},
|
||||
isMobile: false,
|
||||
isInitialized: false,
|
||||
updateProfile: async () => {},
|
||||
updatePreferences: async () => {},
|
||||
clearError: () => {}
|
||||
updateProfile: async () => { },
|
||||
updatePreferences: async () => { },
|
||||
clearError: () => { }
|
||||
});
|
||||
|
||||
export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
@@ -63,7 +66,7 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let userInfo: User | null = null; // Declare at function scope
|
||||
try {
|
||||
logger.debug('user-context', '🔄 Resolving user profile', {
|
||||
@@ -110,30 +113,30 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
email: userInfo.email
|
||||
});
|
||||
|
||||
let profileRow: Record<string, unknown> | null = null;
|
||||
let profileRow: Record<string, unknown> | null = null;
|
||||
|
||||
logger.debug('user-context', '🔧 Step 5: Querying profiles table...', {
|
||||
userId: userInfo.id
|
||||
});
|
||||
|
||||
|
||||
// Set loading state when we start the actual database query
|
||||
setLoading(true);
|
||||
|
||||
|
||||
// Query profiles table without timeout to see actual error
|
||||
logger.debug('user-context', '🔧 Step 5b: Starting profiles query...', {
|
||||
userId: userInfo.id,
|
||||
clientType: 'authenticated'
|
||||
});
|
||||
|
||||
|
||||
// Try direct fetch instead of Supabase client to bypass hanging issue
|
||||
logger.debug('user-context', '🔧 Step 5b1: About to make profiles query with direct fetch...', {
|
||||
userId: userInfo.id,
|
||||
queryStarted: true
|
||||
});
|
||||
|
||||
const { data, error } = await fetch(`http://localhost:8000/rest/v1/profiles?select=*&id=eq.${userInfo.id}`, {
|
||||
|
||||
const { data, error } = await fetch(`${supabaseUrl}/rest/v1/profiles?select=*&id=eq.${userInfo.id}`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0`,
|
||||
'Authorization': `Bearer ${supabaseAnonKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
@@ -151,20 +154,20 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
});
|
||||
return { data: null, error: { message: err.message, code: 'FETCH_ERROR' } };
|
||||
});
|
||||
|
||||
|
||||
logger.debug('user-context', '🔧 Step 5b2: Direct fetch completed...', {
|
||||
userId: userInfo.id,
|
||||
hasData: !!data,
|
||||
hasError: !!error
|
||||
});
|
||||
|
||||
|
||||
logger.debug('user-context', '🔧 Step 5c: Profiles query completed', {
|
||||
hasData: !!data,
|
||||
hasError: !!error,
|
||||
errorCode: error?.code,
|
||||
errorMessage: error?.message
|
||||
});
|
||||
|
||||
|
||||
logger.debug('user-context', '🔧 Step 5a: Profiles query result', {
|
||||
hasData: !!data,
|
||||
hasError: !!error,
|
||||
@@ -316,7 +319,7 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
userId: userInfo?.id,
|
||||
email: userInfo?.email
|
||||
});
|
||||
|
||||
|
||||
if (userInfo) {
|
||||
const metadata = userInfo.user_metadata as CCUserMetadata;
|
||||
const fallbackProfile: CCUser = {
|
||||
@@ -330,12 +333,12 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
created_at: userInfo.created_at,
|
||||
updated_at: userInfo.updated_at
|
||||
};
|
||||
|
||||
|
||||
DatabaseNameService.rememberDatabaseNames({
|
||||
userDbName: fallbackProfile.user_db_name,
|
||||
schoolDbName: fallbackProfile.school_db_name
|
||||
});
|
||||
|
||||
|
||||
setProfile(fallbackProfile);
|
||||
logger.debug('user-context', '✅ Fallback profile created', {
|
||||
userId: fallbackProfile.id,
|
||||
@@ -345,7 +348,7 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
} else {
|
||||
setProfile(null);
|
||||
}
|
||||
|
||||
|
||||
setPreferences({});
|
||||
setError(error instanceof Error ? error : new Error('Failed to load user profile'));
|
||||
setLoading(false); // Ensure loading is cleared on error
|
||||
@@ -353,12 +356,12 @@ export const UserProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
logger.debug('user-context', '🔧 Finalizing user context initialization...', {
|
||||
isMounted: mountedRef.current
|
||||
});
|
||||
|
||||
|
||||
if (mountedRef.current) {
|
||||
// Loading state is already managed above, just log completion
|
||||
logger.debug('user-context', '✅ User context initialization complete');
|
||||
}
|
||||
|
||||
|
||||
logger.debug('user-context', '🔧 Step 10: Setting isInitialized to true');
|
||||
setIsInitialized(true);
|
||||
logger.debug('user-context', '✅ User context initialized flag set - initialization complete!', {
|
||||
|
||||
Reference in New Issue
Block a user