Skip to main content
Function Signature
A PortalAuth method. Removes the session persisted for this authEnvironmentId, and forgets the grant this instance last exchanged (through confirmMagicLink, completeOAuthLogin or signInWith*) and any session from an accepted two-factor code that is still waiting to be written to the Keychain, so neither a redirect re-delivered after sign-out nor a repeated verifyTotp can bring back the session that was just cleared. It also cancels a Google or Apple sign-in in progress. Throws
  • PortalAuthError.sessionStorageFailure(message:): A Keychain delete failed. Both the session and the sign-in in progress are always attempted; when both fail, the session’s failure is the one thrown.
Notes
  • Cancels a Google or Apple sign-in in progress, including one completeOAuthLogin or signInWith* is already exchanging on this instance, which then throws PortalAuthError.oauthFlowNotStarted instead of returning a session. Wait for it to return before starting a new sign-in, and do not call it in your redirect handler before completeOAuthLogin. Calling it after loginWithGoogle() / loginWithApple() has returned a URL, or while a sign-in sheet is open, abandons that sign-in. A sign-in already at its two-factor step is not cancelled: its grant is already spent, and verifyTotp can still complete it, so to abandon it, discard its userJwt. An exchange already in flight on another PortalAuth instance with the same Auth Environment ID is not cancelled either. Available starting from SDK version 8.2.0.
  • Call it on sign-out, alongside portal.clearSession(), and from your onSessionInvalidated listener before you show the sign-in screen. Portal.clearSession() invalidates the credential the Portal holds but does not reach what PortalAuth keeps: its memory of the last grant it exchanged, a session from an accepted two-factor code still waiting to be written, a session a sign-in stored after that Portal was built, or a Google or Apple sign-in in progress.
  • It is not a sign-out on its own. It does not affect a Portal that already holds the session (there is no server-side revoke); it prevents a future restoreSession() from returning it. Use portal.clearSession() for the live instance.
  • Waits for an exchange already running on this instance — from confirmMagicLink or verifyTotp — to finish persisting, then deletes the session it persisted. A Google or Apple exchange on this instance is cancelled instead, as above. An exchange on another PortalAuth instance with the same Auth Environment ID is neither waited for nor cancelled: it completes, and the session it stores survives until that auth environment is cleared again, so on sign-out call clearPersistedSession() on every instance. A signInWith* sheet that is still open is cancelled too, so its callback is refused, but the sheet stays on screen: on sign-out, cancel its task first. A sheet closed before it returns a result exchanges nothing.
  • A completion that finishes while this waits still returns its session to its caller, and that session keeps working in memory. If your app signed out while it ran, discard the result instead of adopting it.
  • After it, confirming the same magic link again sends the spent grant to Portal, which rejects it with PortalAuthError.grantRejected. Completing the same Google or Apple redirect again throws PortalAuthError.oauthFlowNotStarted without a request, or PortalRequestsError.unauthorized from Portal if a newer sign-in is in progress.
  • If your app remembers which magic link the user confirmed, forget it on sign-out too.
  • Keychain items survive app deletion, so calling this on the first launch after install gives a fresh install a clean slate.
  • Available starting from SDK version 8.0.0.
Example Usage
Related Documentation