Access App With Cached Role State While Offline
The Role Config Store provides a local cache layer for role and membership data fetched from Supabase. When the device loses connectivity, the app reads the cached role state from local storage to determine access levels and organizational context. This allows peer mentors working in the field to register activities and access their assigned contacts even without an active internet connection. The cache is invalidated when the user switches roles or when the session expires, ensuring stale role data is not used after credential changes.
User Story
Acceptance Criteria
- Given a user has previously authenticated and their role data has been cached, when the device goes offline, then the app continues to function with the cached role and organization context
- Given the device is offline and the user navigates to a protected route, when the Permission Guard evaluates access, then it uses the cached role data from the Role Config Store
- Given the device reconnects to the network, when the session is active, then the Role Config Store is refreshed with the latest role data from Supabase
- Given the user switches roles while online, when the switch completes, then the Role Config Store cache is invalidated and refreshed with the new active role
- Given the cached session has expired after an extended offline period, when the user attempts to access a protected route, then they are redirected to the login screen rather than using expired cached credentials
Business Value
Peer mentors use the app in the field during home visits and community events where connectivity may be unreliable. Without offline role caching, any connectivity interruption would lock them out of the app, making it unusable in real-world conditions. This is particularly critical for Norwegian users in rural areas or older users relying on less reliable mobile infrastructure.
Components
- Role Config Store data
- User Role Repository data
- Role Authorization Service service