Authentication
How authentication works between Universe Shell and your module. postMessage protocol, ShellAuthProvider, and session management.
Authentication
Your module runs inside an iframe embedded in Universe Shell. Authentication happens automatically through a postMessage protocol — no OAuth setup, no API keys to manage.
How It Works
ShellAuthProvider
The ShellAuthProvider component handles the entire authentication flow. It's included in the module-starter template at src/lib/shell-auth.tsx.
useShellAuth Hook
Access authentication state anywhere in your module:
Context Type
Organization ID
The organizationId identifies which tenant (company) the user belongs to. It's passed via the iframe URL parameter ?org_id=<uuid>.
Always use organizationId when querying data. This ensures tenant isolation — users can only see data belonging to their organization.
Security Considerations
Origin Validation
The current implementation uses '*' as the target origin in postMessage. For production modules, validate the origin:
Token Refresh
Supabase tokens have a limited lifetime. The ShellAuthProvider handles initial session setup, but for long-running sessions, the Supabase client auto-refreshes tokens in the background.
Never Expose Tokens
- Don't store tokens in
localStorage(the Shell manages the source of truth) - Don't log tokens to the console in production
- Don't send tokens to third-party services