Overview
GreenhouseAdmin uses JWT (JSON Web Token) authentication with secure token storage across all platforms. TheAuthRepository handles all authentication operations including login, logout, and session validation.
AuthRepository Interface
TheAuthRepository interface defines the contract for authentication operations:
Authentication Flow
1. Login
The login flow authenticates the user and stores the JWT token securely:2. Token Storage
Tokens are stored securely using platform-specific mechanisms:- Android
- iOS
- Web
3. Using Stored Tokens
The HTTP client automatically attaches the JWT token to all authenticated requests:4. Logout
Logout clears the server session and local tokens:5. Session Validation
Validate the current session to check if the token is still valid:Data Models
JwtResponse
Response from the login API:UserSession
Represents the authenticated user session in the app:Usage Examples
Login Screen ViewModel
Protected Screen ViewModel
Navigation Guard
Token Expiration Handling
When a token expires, the API returns a 401/403 status. The HTTP client intercepts this and triggers session cleanup:Security Best Practices
Secure Token Storage
Secure Token Storage
- Android: Use
EncryptedSharedPreferencesinstead of plain SharedPreferences - iOS: Always use Keychain, never UserDefaults
- Web: Consider
sessionStoragefor more sensitive apps (cleared on tab close) - Never log tokens or store them in plain text
Token Lifecycle
Token Lifecycle
- Clear tokens on logout (both local and server-side)
- Validate tokens before critical operations
- Handle token expiration gracefully
- Implement token refresh if your backend supports it
HTTPS Only
HTTPS Only
- Always use HTTPS in production
- Never transmit tokens over unencrypted connections
- Pin SSL certificates for additional security
Role-Based Access
Role-Based Access
API Reference
AuthApiService
Low-level API service used byAuthRepository:
Related Documentation
API Overview
Learn about the repository pattern architecture
UsersRepository
Manage user accounts and roles
ClientsRepository
Manage greenhouse clients and tenants
Data Models
Explore authentication data models