Swift Session Management
Guide to managing authentication sessions in Para for Swift applications
Para Swift SDK provides robust session management, automatically tracking authentication states and ensuring secure, seamless interactions. Effective session management is critical for security, usability, and reliability of your application.
Session States
Para manages sessions using the ParaSessionState
enum:
unknown
: Initial state before the status is determined.inactive
: SDK initialized but no active session.active
: Session is active but user not fully logged in.activeLoggedIn
: User is fully logged in with an active session.
Observing Session States
Utilize SwiftUI’s Combine or other state management tools to observe changes:
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.
Key Session Methods
isSessionActive() async throws -> Bool
: Checks if the session is currently valid before performing authenticated operations.isFullyLoggedIn() async throws -> Bool
: Checks if the user is fully logged in with an active session.exportSession() async throws -> String
: Exports session state as a string that can be used for advanced integration scenarios.logout() async throws
: Clears the current session, removes all website data from the WebView, and resets the session state to inactive.
Maintaining Active Sessions
For long-running applications, check session status before performing sensitive operations:
Refreshing Expired Sessions
When a session has expired, Para recommends initiating a full authentication flow rather than trying to refresh the session.
For Swift applications, always call logout()
before reinitiating authentication when a session has expired to ensure all stored data is properly cleared.
Background Security
Clear sensitive data when app goes to background by logging out:
Exporting Sessions to Your Server
In some advanced scenarios, you may need to export the session state:
Best Practices
Check Sessions on App Launch
Verify session status when your app starts to determine if users need to reauthenticate:
Handle App Lifecycle Changes
Swift apps can be backgrounded and foregrounded, which may affect session status:
Next Steps
Explore more advanced features and integrations with Para in Swift: