Multi-tenant B2B User Management & Access Control
Rebuilt B2B identity for multi-tenant roles: one login across companies, finer access control, and support for role-based plans.
Rejected path: Copy login and session helpers into each microfrontend
Overview
I owned the Astro/React identity microfrontend and shared auth package for a B2B identity change, working with backend and security: from isolated nick accounts (one nick, one company, everyone admin) to email-based multi-tenant access where one identity holds roles across companies.
Problem
Users logged in with a nick, and one nick meant one company. Everyone was admin because there were no restricted roles. As the platform grew, businesses needed finer access control and one person managing more than one company.
Constraints
- The change touched every microfrontend that showed login or a user name.
- Backend owned Keycloak enforcement; frontend needed a shared library to read the new session states.
- No big-bang release. Gradual rollout without breaking active legacy sessions.
Architecture
With backend and security, we built registration, login, and role assignment as a central Astro/React microfrontend, plus an internal JS library for auth validation and Keycloak. That library exported shared User Profile and Login components injected across other microfrontends.
Key Decisions
Auth in an internal package
One place for validation, Keycloak calls, and auth UI beats copying login logic across microfrontends.
- Copy login and session helpers into each microfrontend (rejected: code drifts apart and raises security risk)
- Single SPA shell owning all auth UI (rejected: too coupled to platform migration)
Atoms for local React state, Astro elsewhere
Multi-step registration needed shared state inside one React app. Atoms fit that without inventing cross-island persistence.
- Redux/global store across microfrontends (rejected: overkill and boundary leak)
Phased rollout
Identity pieces went to production in stages so legacy sessions kept working.
- Big-bang cutover (rejected: too much session risk)
Tech stack
- Astro
- React
- TypeScript
- Internal Atom-based State Management
- Keycloak (Auth integration)
- Tailwind CSS
Impact
Identity went from 1 nick = 1 company to 1 email = multiple companies with roles. That model enabled plans that depend on roles and companies managed.
Learnings
- Microfrontends work when boundaries are clear. Auth crosses them, so a shared library was the right fix.
- Phased identity rollout lowers the risk of migrating legacy auth.
- Keycloak owns the truth; how the frontend reads claims still decides whether login and profile UI stay consistent across microfrontends.