Enhance authentication/authorization documentation and examples
#524 opened on Jul 27, 2025
Repository metrics
- Stars
- (3,599 stars)
- PR merge metrics
- (PR metrics pending)
Description
Summary
Improve documentation and examples for authentication and authorization patterns in Livestore applications. While Livestore intentionally keeps auth out of scope for maximum flexibility, we need comprehensive guidance on implementing various auth scenarios using the available hooks and building blocks.
Current State
✅ What we have:
- Basic auth pattern with JWT validation (
docs/patterns/auth.md) - Anonymous user transition pattern
- Connection-level validation via
validatePayload - Event-level validation hooks (
onPush,onPull) - Simple token examples in sync provider templates
❌ What's missing:
- Advanced authorization patterns (RBAC, resource-level permissions)
- Real-world auth provider integrations
- Per-event authorization examples
- Multi-tenant authorization strategies
- Complete full-stack auth examples
- Auth testing patterns
Ideas for Improvement
Note: These are suggestions, not requirements. Any step in this direction is helpful! We should be mindful about not being exhaustive to keep maintenance burden manageable.
Documentation Ideas
Some patterns that could be valuable to document:
- Role-based access control (RBAC) examples
- Multi-tenant authorization strategies
- Integration approaches with popular auth providers (Auth0, Supabase, Clerk)
- Token refresh and session management patterns
- Per-event authorization using
onPush/onPullhooks - Testing strategies for auth scenarios
Example Projects
Rather than maintaining many examples in the main repo, we could:
- Create a few focused examples that demonstrate core patterns
- Encourage community examples as separate repositories
- Maintain a curated list of community auth implementations
- Share real-world integration patterns from the community
Potential Building Blocks
Some utilities that might be helpful (could be separate packages):
- Auth hooks for common client-side patterns
- Permission checking helpers for server-side validation
- Testing utilities for auth scenarios
Auth Scenarios Worth Exploring
Connection-Level Auth
- User authentication on initial connection
- JWT validation and user identification
- Graceful fallback to local-only mode
Event-Level Authorization
- Per-push validation using
onPushhook - Resource ownership checking
- Field-level permissions
Multi-Tenancy
- Store isolation by organization/workspace
- Shared vs private data patterns
- Cross-tenant permissions
Advanced Patterns
- Hierarchical permissions (org → team → user)
- Time-based access control
- Audit logging and compliance
Contributing & Community Examples
We especially encourage external projects and examples! This helps keep the main repo focused while building a rich ecosystem of auth patterns.
Ways to contribute:
- Share your auth implementation as a separate repository
- Write blog posts about your Livestore auth patterns
- Create reusable packages for common auth scenarios
- Submit focused PRs for core documentation improvements
- Comment on this issue with your auth use case or questions
Community examples we'd love to see:
- Auth0 + Livestore starter template
- Supabase integration example
- Multi-tenant SaaS application
- Real-world RBAC implementation
- Testing patterns for authenticated apps
Philosophy: Auth remains intentionally out of Livestore's core scope for maximum flexibility. This issue is about providing just enough guidance to get started, while encouraging the community to build and share complete solutions as separate projects.