React Native Session Management
Guide to managing authentication sessions in Para for React Native applications
Para provides a comprehensive set of methods for managing authentication sessions in React Native applications. These sessions are crucial for secure transaction signing and other authenticated operations.
Session Duration
The Para session length is 2 hours
by default, but can be configured to up to 30 days. To configure this parameter, please visit the Configuration section of the Developer Portal. A user signing a message or transaction extends the session by the duration of the session length.
Managing Sessions
Checking Session Status
Use isSessionActive()
to verify whether a userβs session is currently valid before performing authenticated operations.
In React Native applications, itβs especially important to check the session status before allowing users to access authenticated areas of your app due to the persistence of local storage between app launches.
Example usage:
Maintaining Active Sessions
Para provides the keepSessionAlive()
method to extend an active session without requiring full reauthentication.
Example usage:
Refreshing Expired Sessions
When a session has expired, Para recommends initiating a full authentication flow rather than trying to refresh the session.
For React Native applications, always call logout()
before reinitiating authentication when a session has expired to ensure all stored data is properly cleared.
Exporting Sessions to Your Server
Use exportSession()
when you need to transfer session state to your server for performing operations on behalf of the user.
If your server doesnβt need to perform signing operations, use { excludeSigners: true }
when exporting sessions for enhanced security.
Example implementation:
Best Practices for React Native
- Check Sessions on App Launch: Verify session status when your app starts to determine if users need to reauthenticate.
- Implement Automatic Session Extension: For long app usage sessions, periodically call
keepSessionAlive()
to prevent unexpected session expirations.
- Handle Background/Foreground State: React Native apps can be backgrounded and foregrounded, which may affect session status.
- Secure Storage Configuration: For enhanced security, consider implementing a custom storage solution to manage sensitive session data.
Next Steps:
Explore more advanced features and integrations with Para in Flutter: