File size: 382 Bytes
e289c5c | 1 2 3 4 5 6 7 8 9 10 11 12 | import { AsyncLocalStorage } from 'async_hooks';
export const tenantContext = new AsyncLocalStorage<{ organizationId: string }>();
export const runWithTenant = <T>(organizationId: string, fn: () => T): T => {
return tenantContext.run({ organizationId }, fn);
};
export const getOrganizationId = (): string | undefined => {
return tenantContext.getStore()?.organizationId;
};
|