This commit is contained in:
seb
2026-10-28 19:31:41 +01:00
parent 01d6aa0e3f
commit 1881830b0a
13 changed files with 81 additions and 27 deletions

View File

@@ -3,6 +3,8 @@ import { MssqlProvider } from 'libdashstore/providers/mssql';
import { BetterSqlite3Provider } from 'libdashstore/providers/better-sqlite3';
import env from '../config/env.js';
import { createLogger, chalk } from '../util/logger.js';
import { clearCachedCompanyUsers, clearCachedUser } from '../api/middleware/auth.js';
import { clearDeletedCompany, setUserCompany } from '../api/sse.js';
const storeLog = createLogger('libstore');
@@ -79,6 +81,22 @@ function wrapStoreWithTiming(rawStore) {
try {
const result = await fn(...args);
storeLog.debug(`${namespace}.${method} ${chalk.gray(`(${Date.now() - start}ms)`)}`);
if (namespace === 'google_auth' && method === 'setSelectedCompany') {
const [googleAuthId, companyId] = args;
if (googleAuthId != null) {
const normalizedUserId = Number(googleAuthId);
const normalizedCompanyId = companyId != null ? Number(companyId) : null;
clearCachedUser(normalizedUserId);
setUserCompany(normalizedUserId, normalizedCompanyId);
}
} else if (namespace === 'company' && method === 'delete') {
const [companyId] = args;
if (companyId != null) {
const normalizedCompanyId = Number(companyId);
clearCachedCompanyUsers(normalizedCompanyId);
clearDeletedCompany(normalizedCompanyId);
}
}
return result;
} catch (err) {
const isNotFound = /not found/i.test(err?.message);