fix: remove authservice injection on userRepo
This commit is contained in:
		
							parent
							
								
									a2f57cbfa9
								
							
						
					
					
						commit
						94ae002d83
					
				@ -3,15 +3,19 @@ const firebaseRepository = require('./firebase.repository');
 | 
			
		||||
 | 
			
		||||
let authService = null;
 | 
			
		||||
 | 
			
		||||
function setAuthService(service) {
 | 
			
		||||
    authService = service;
 | 
			
		||||
function getAuthService() {
 | 
			
		||||
    if (!authService) {
 | 
			
		||||
        authService = require('../../services/authService');
 | 
			
		||||
    }
 | 
			
		||||
    return authService;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getBaseRepository() {
 | 
			
		||||
    if (!authService) {
 | 
			
		||||
        throw new Error('AuthService has not been set for the user repository.');
 | 
			
		||||
    const service = getAuthService();
 | 
			
		||||
    if (!service) {
 | 
			
		||||
        throw new Error('AuthService could not be loaded for the user repository.');
 | 
			
		||||
    }
 | 
			
		||||
    const user = authService.getCurrentUser();
 | 
			
		||||
    const user = service.getCurrentUser();
 | 
			
		||||
    if (user && user.isLoggedIn) {
 | 
			
		||||
        return firebaseRepository;
 | 
			
		||||
    }
 | 
			
		||||
@ -25,24 +29,23 @@ const userRepositoryAdapter = {
 | 
			
		||||
    },
 | 
			
		||||
    
 | 
			
		||||
    getById: () => {
 | 
			
		||||
        const uid = authService.getCurrentUserId();
 | 
			
		||||
        const uid = getAuthService().getCurrentUserId();
 | 
			
		||||
        return getBaseRepository().getById(uid);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    update: (updateData) => {
 | 
			
		||||
        const uid = authService.getCurrentUserId();
 | 
			
		||||
        const uid = getAuthService().getCurrentUserId();
 | 
			
		||||
        return getBaseRepository().update({ uid, ...updateData });
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    deleteById: () => {
 | 
			
		||||
        const uid = authService.getCurrentUserId();
 | 
			
		||||
        const uid = getAuthService().getCurrentUserId();
 | 
			
		||||
        return getBaseRepository().deleteById(uid);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    ...userRepositoryAdapter,
 | 
			
		||||
    setAuthService
 | 
			
		||||
    ...userRepositoryAdapter
 | 
			
		||||
}; 
 | 
			
		||||
@ -4,7 +4,6 @@ const { getFirebaseAuth } = require('./firebaseClient');
 | 
			
		||||
const fetch = require('node-fetch');
 | 
			
		||||
const encryptionService = require('./encryptionService');
 | 
			
		||||
const migrationService = require('./migrationService');
 | 
			
		||||
const userRepository = require('../repositories/user');
 | 
			
		||||
const sessionRepository = require('../repositories/session');
 | 
			
		||||
const providerSettingsRepository = require('../repositories/providerSettings');
 | 
			
		||||
const userModelSelectionsRepository = require('../repositories/userModelSelections');
 | 
			
		||||
@ -47,7 +46,6 @@ class AuthService {
 | 
			
		||||
        encryptionService.initializeKey(this.currentUserId);
 | 
			
		||||
        this.initializationPromise = null;
 | 
			
		||||
 | 
			
		||||
        userRepository.setAuthService(this);
 | 
			
		||||
        sessionRepository.setAuthService(this);
 | 
			
		||||
        providerSettingsRepository.setAuthService(this);
 | 
			
		||||
        userModelSelectionsRepository.setAuthService(this);
 | 
			
		||||
@ -56,12 +54,6 @@ class AuthService {
 | 
			
		||||
    initialize() {
 | 
			
		||||
        if (this.isInitialized) return this.initializationPromise;
 | 
			
		||||
 | 
			
		||||
        // --- Break the circular dependency ---
 | 
			
		||||
        // Inject this authService instance into the session repository so it can be used
 | 
			
		||||
        // without a direct `require` cycle.
 | 
			
		||||
        sessionRepository.setAuthService(this);
 | 
			
		||||
        // --- End of dependency injection ---
 | 
			
		||||
 | 
			
		||||
        this.initializationPromise = new Promise((resolve) => {
 | 
			
		||||
            const auth = getFirebaseAuth();
 | 
			
		||||
            onAuthStateChanged(auth, async (user) => {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user