Developer
Authentication Documentation
This directory contains comprehensive documentation for the Kulcare platform's authentication system.
Table of Contents
Core Documentation
-
- Complete technical overview of the auth system
- State management with Zustand
- Token management and security
- API integration details
- Implementation guide with code examples
-
- User journey from login to accessing protected resources
- Cross-app authentication sharing
- Standalone vs federated mode handling
- Clinic selection process
-
- Comprehensive logout functionality
- Complete data clearing from browser storage
- Cross-tab synchronization
- Event-based architecture
- 401 unauthorized handling
-
- Complete change password implementation
- Clean architecture with separation of concerns
- Real-time password validation
- Custom hook pattern for business logic
- Security best practices
Implementation Guides
-
- Step-by-step plan for implementing login
- Component structure
- API integration approach
-
- Summary of implemented login features
- Key decisions and patterns used
Testing Documentation
-
- Test strategies for auth flows
- Unit and integration test examples
- Mock data setup
-
- Specific login testing scenarios
- E2E test examples
Technical References
-
- Cross-origin resource sharing configuration
- API client setup for CORS
-
- Sample login implementation code
- Reference for developers
Roles and Permissions
- Roles and Permissions (RBAC)
- The model: roles, permission keys, tenant rows, and per-user overrides
- The resolution order and the
GET /identity/my/permissionsendpoint - How to add a key, change a default, and gate an action
- The grant ceiling, invites, the tests, and the deploy step
- Pundit rules: Authorization (Pundit policies)
Quick Start
For developers implementing authentication features:
- Start with Authentication Architecture for overall understanding
- Review Authentication Flow for user journey
- Check Logout Implementation for proper session termination
- See Change Password for password management implementation
- Use Testing Authentication for test implementation
Key Features
- 🔐 JWT-based authentication with automatic token refresh
- 🏥 Multi-clinic support for healthcare providers
- 👥 Role-based access control (RBAC)
- 💾 Persistent sessions across page refreshes
- 🔄 Cross-tab synchronization for consistent state
- 🚪 Comprehensive logout with complete data clearing
- 🛡️ Security-first design with proper token handling
Security Considerations
- Always use HTTPS in production
- Tokens are stored securely in localStorage
- Automatic logout on 401 responses
- Complete session termination on logout
- No sensitive data persisted after logout
Integration with Micro-Frontends
The authentication system is designed to work seamlessly across all micro-frontends:
- Shell App: Handles login, logout, and clinic selection
- CMS App: Protected routes require authentication
- Growth App: Shares authentication state with other apps
- Future Apps: Will integrate the same auth patterns
All apps use the @kulcare/auth package for consistent authentication handling.