Skip to main content
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

Para session length is configured per API key and can be set up to 30 days through the Configuration section of the or CLI. The Para API enforces the configured duration. Signing a message or transaction, or calling the session keep-alive method, can extend an active session according to that configuration.

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: