
*By Sean Erick C. Ramones, Vue SME | JavaScript/TypeScript SME*
Sean Erick C. Ramones
Multi-tenancy is an architecture where a single app instance serves multiple clients (tenants). Each tenant behaves like it has its own isolated version of the app.
You might have seen urls like this in Jira, Github, Slack, etc. Each tenant accesses the platform via their own subdomain, like:
mllr.preesh.com
acme.preesh.com
some-other-org.preesh.com
// middleware/tenant.ts
export default defineNuxtRouteMiddleware(() => {
const host = useRequestHeaders()['host'] || '';
const [subdomain] = host.split('.');
const knownTenants = useRuntimeConfig().public.knownTenants || [];
if (!knownTenants.includes(subdomain)) return navigateTo('/invalid-tenant');
useState('tenant', () => subdomain);
});
// nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/*': { middleware: ['tenant'] },
},
runtimeConfig: {
public: {
knownTenants: ['acme', 'globex']
}
}
});
We can define per-tenant branding that influences UI themes, logos, and color schemes.
// composables/useTenantConfig.ts
export const useTenantConfig = () => {
const tenant = useState('tenant');
const map = {
acme: { color: '#FF5733', logo: '/acme-logo.svg' },
globex: { color: '#3333FF', logo: '/globex-logo.svg' }
}; // Ideally pulled from a DB or config API
return map[tenant.value];
};
Use this config in layout and theming logic for dynamic styles and assets.
// middleware/role.ts
export default defineNuxtRouteMiddleware(() => {
const user = useState('user').value;
if (!user || user.role !== 'HR_ADMIN') return navigateTo('/unauthorized');
});
To prevent cross-tenant data leakage and protect user data:
tenant_idEach key entity must include a tenant_id to isolate data:
CREATE TABLE users (
id UUID PRIMARY KEY,
tenant_id UUID NOT NULL,
role TEXT
);
CREATE TABLE cards (
id UUID PRIMARY KEY,
tenant_id UUID NOT NULL,
created_by UUID,
message TEXT
);
*.preesh.comNuxt Labs recently joined Vercel, which may improve official support for:
While current tenant configs (e.g., themes, logos) are manually defined, a future enhancement could allow tenants to edit their own configuration dynamically. This can be achieved using Nuxt Content as a lightweight CMS for managing per-tenant markdown/config content.
We could also allow tenants to add sub-pages, custom messages, or FAQ sections using markdown files per tenant.
This multi-tenant Nuxt setup enables Preesh to scale efficiently as a SaaS tool for HR departments, with:
Future upgrades may include self-service onboarding, tenant CMS integration, and more flexible customization per company.