Skip to content

BaseContext exposes tenantId/tenantLevel/role regardless of app configuration #2004

@viniciusdacal

Description

@viniciusdacal

Description

BaseContext in packages/server/src/entity/types.ts hardcodes auth and tenancy fields that every EntityContext and ServiceContext inherits:

export interface BaseContext {
  readonly userId: string | null;
  readonly tenantId: string | null;
  readonly tenantLevel?: string | null;
  authenticated(): boolean;
  tenant(): boolean;
  role(...roles: string[]): boolean;
}

These fields appear on every handler ctx parameter — even in apps that have no auth or tenancy configured. This is misleading: a developer sees ctx.tenantId in autocomplete and assumes multi-tenancy is active, when in reality it's always null.

Problem

  • DX noise — simple apps see auth/tenancy properties they never configured
  • Misleadingctx.role('admin') suggests role-based auth is available when it isn't
  • Not inferrable — there's no generic parameter or configuration point to control what's on the context

Possible directions

  1. Make BaseContext generic — derive the shape from server/auth/tenancy configuration so only configured features appear on ctx
  2. Split into mixinsAuthContext, TenantContext etc. that get composed based on config
  3. Keep as-is but document — accept the nullable fields as a universal interface (simplest, least work)

Found during

Typed action I/O work (#2003) — noticed while reviewing hover types in a demo app with no auth configured.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions