latest
This commit is contained in:
@@ -44,11 +44,19 @@ export function convertToCCUser(user: User, metadata: CCUserMetadata): CCUser {
|
||||
// Default to student if no user type specified
|
||||
const userType = metadata.user_type || 'student';
|
||||
|
||||
const userDbName = DatabaseNameService.getUserPrivateDB(
|
||||
const storedUserDb = DatabaseNameService.getStoredUserDatabase();
|
||||
const storedSchoolDb = DatabaseNameService.getStoredSchoolDatabase();
|
||||
|
||||
const userDbName = storedUserDb || DatabaseNameService.getUserPrivateDB(
|
||||
userType,
|
||||
username
|
||||
user.id
|
||||
);
|
||||
const schoolDbName = DatabaseNameService.getDevelopmentSchoolDB();
|
||||
const schoolDbName = metadata.school_db_name || metadata.worker_db_name || storedSchoolDb || '';
|
||||
|
||||
DatabaseNameService.rememberDatabaseNames({
|
||||
userDbName,
|
||||
schoolDbName
|
||||
});
|
||||
|
||||
return {
|
||||
id: user.id,
|
||||
@@ -222,6 +230,7 @@ class AuthService {
|
||||
storageService.set(StorageKeys.USER_ROLE, ccUser.user_type);
|
||||
storageService.set(StorageKeys.USER, ccUser);
|
||||
storageService.set(StorageKeys.SUPABASE_TOKEN, data.session.access_token);
|
||||
storageService.set(StorageKeys.SUPABASE_SESSION, data.session);
|
||||
|
||||
logger.info('auth-service', '✅ Login successful', {
|
||||
userId: ccUser.id,
|
||||
@@ -262,4 +271,3 @@ class AuthService {
|
||||
}
|
||||
|
||||
export const authService = AuthService.getInstance();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { TLUserPreferences, TLUser } from '@tldraw/tldraw';
|
||||
import { Session } from '@supabase/supabase-js';
|
||||
import { CCUser } from '../../services/auth/authService';
|
||||
import { logger } from '../../debugConfig';
|
||||
|
||||
@@ -8,6 +9,7 @@ export enum StorageKeys {
|
||||
USER = 'user',
|
||||
USER_ROLE = 'user_role',
|
||||
SUPABASE_TOKEN = 'supabase_token',
|
||||
SUPABASE_SESSION = 'supabase_session',
|
||||
MS_TOKEN = 'msAccessToken',
|
||||
NEO4J_USER_DB = 'neo4jUserDbName',
|
||||
NEO4J_WORKER_DB = 'neo4jWorkerDbName',
|
||||
@@ -27,6 +29,7 @@ interface StorageValueTypes {
|
||||
[StorageKeys.USER]: CCUser;
|
||||
[StorageKeys.USER_ROLE]: string;
|
||||
[StorageKeys.SUPABASE_TOKEN]: string;
|
||||
[StorageKeys.SUPABASE_SESSION]: Session;
|
||||
[StorageKeys.MS_TOKEN]: string;
|
||||
[StorageKeys.NEO4J_USER_DB]: string;
|
||||
[StorageKeys.NEO4J_WORKER_DB]: string;
|
||||
|
||||
@@ -3,9 +3,10 @@ import { CCUser, convertToCCUser } from '../../services/auth/authService';
|
||||
import { EmailCredentials } from '../../services/auth/authService';
|
||||
import { formatEmailForDatabase } from '../graph/neoDBService';
|
||||
import { RegistrationResponse } from '../../services/auth/authService';
|
||||
import { neoRegistrationService } from '../graph/neoRegistrationService';
|
||||
import { storageService, StorageKeys } from './localStorageService';
|
||||
import { logger } from '../../debugConfig';
|
||||
import { provisionUser } from '../provisioningService';
|
||||
import { DatabaseNameService } from '../graph/databaseNameService';
|
||||
|
||||
const REGISTRATION_SERVICE = 'registration-service';
|
||||
|
||||
@@ -76,38 +77,50 @@ export class RegistrationService {
|
||||
|
||||
storageService.set(StorageKeys.IS_NEW_REGISTRATION, true);
|
||||
|
||||
let provisioningToken = authData.session?.access_token || null;
|
||||
if (!provisioningToken) {
|
||||
const { data: sessionData } = await supabase.auth.getSession();
|
||||
provisioningToken = sessionData.session?.access_token || null;
|
||||
}
|
||||
|
||||
// 3. Create Neo4j nodes
|
||||
try {
|
||||
const userNode = await neoRegistrationService.registerNeo4JUser(
|
||||
ccUser,
|
||||
username, // Pass username for database operations
|
||||
credentials.role
|
||||
);
|
||||
|
||||
logger.info(REGISTRATION_SERVICE, '✅ Registration successful with Neo4j setup', {
|
||||
const provisioned = await provisionUser(ccUser.id, provisioningToken);
|
||||
if (provisioned) {
|
||||
ccUser.user_db_name = provisioned.user_db_name;
|
||||
if (provisioned.worker_db_name) {
|
||||
ccUser.school_db_name = provisioned.worker_db_name;
|
||||
}
|
||||
DatabaseNameService.rememberDatabaseNames({
|
||||
userDbName: ccUser.user_db_name,
|
||||
schoolDbName: ccUser.school_db_name
|
||||
});
|
||||
logger.info(REGISTRATION_SERVICE, '✅ Provisioning successful', {
|
||||
userId: ccUser.id,
|
||||
userDbName: provisioned.user_db_name,
|
||||
workerDbName: provisioned.worker_db_name
|
||||
});
|
||||
} else {
|
||||
logger.warn(REGISTRATION_SERVICE, '⚠️ Provisioning skipped or pending', { userId: ccUser.id });
|
||||
}
|
||||
} catch (provisionError) {
|
||||
logger.warn(REGISTRATION_SERVICE, '⚠️ Provisioning error', {
|
||||
userId: ccUser.id,
|
||||
hasUserNode: !!userNode
|
||||
error: provisionError
|
||||
});
|
||||
|
||||
return {
|
||||
user: ccUser,
|
||||
accessToken: authData.session?.access_token || null,
|
||||
userRole: credentials.role,
|
||||
message: 'Registration successful'
|
||||
};
|
||||
} catch (neo4jError) {
|
||||
logger.warn(REGISTRATION_SERVICE, '⚠️ Neo4j setup problem', {
|
||||
userId: ccUser.id,
|
||||
error: neo4jError
|
||||
});
|
||||
// Return success even if Neo4j setup is pending
|
||||
return {
|
||||
user: ccUser,
|
||||
accessToken: authData.session?.access_token || null,
|
||||
userRole: credentials.role,
|
||||
message: 'Registration successful - Neo4j setup pending'
|
||||
};
|
||||
}
|
||||
|
||||
DatabaseNameService.rememberDatabaseNames({
|
||||
userDbName: ccUser.user_db_name,
|
||||
schoolDbName: ccUser.school_db_name
|
||||
});
|
||||
|
||||
return {
|
||||
user: ccUser,
|
||||
accessToken: authData.session?.access_token || null,
|
||||
userRole: credentials.role,
|
||||
message: 'Registration successful'
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(REGISTRATION_SERVICE, '❌ Registration failed:', error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user