u
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user