> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift Manage Sessions

> Restore sessions, manage access, and sign out with the Swift OMS Wallet SDK.

Use the Swift SDK session APIs after authentication to restore wallet state, issue ID tokens, and manage credential access.

## Session Restore

The SDK stores wallet metadata and the request-signing credential in the device keychain. A saved completed session is restored automatically when `OMSClient` is created.

```swift theme={null}
let oms = OMSClient(
    publishableKey: "YOUR_PROJECT_ACCESS_KEY",
    projectId: "YOUR_PROJECT_ID"
)

if let walletAddress = oms.wallet.session.walletAddress {
    print("Restored wallet:", walletAddress)
}
```

**Returns**

`oms.wallet.session` returns `SessionState` with `walletAddress`, `expiresAt`, `loginType`, and `sessionEmail`.

## Session Expiry Events

Assign `onSessionExpired` when the app should react as soon as the active wallet session expires.

```swift theme={null}
oms.wallet.onSessionExpired = { event in
    print("Session expired at:", event.expiredAt)
    print("Expired wallet:", event.session.walletAddress ?? "")
}

// Assign nil when the owner no longer needs updates.
oms.wallet.onSessionExpired = nil
```

The SDK replays the latest expired-session event when a handler is assigned until a new auth flow, new wallet session, or sign out clears it.

**Parameters**

| Parameter          | Type                               | Description                                                                               |
| ------------------ | ---------------------------------- | ----------------------------------------------------------------------------------------- |
| `onSessionExpired` | `((SessionExpiredEvent) -> Void)?` | Optional handler that receives `session` and `expiredAt` when the wallet session expires. |

**Returns**

The handler returns `Void`.

## List Wallets

List wallets available to the authenticated credential.

```swift theme={null}
let wallets = try await oms.wallet.listWallets()

for wallet in wallets {
    print(wallet.id, wallet.type, wallet.address)
}
```

**Parameters**

Takes no parameters.

**Returns**

Returns `[Wallet]`.

## Get ID Token

Request an ID token for the active wallet session. Send this token to your backend when using backend wallet verification.

```swift theme={null}
let idToken = try await oms.wallet.getIdToken(ttlSeconds: 300)
```

**Parameters**

| Parameter      | Type                         | Description                                     |
| -------------- | ---------------------------- | ----------------------------------------------- |
| `ttlSeconds`   | `UInt32?`                    | Optional token lifetime in seconds.             |
| `customClaims` | `[String: WebRPCJSONValue]?` | Optional custom claims to include in the token. |

**Returns**

Returns `String`.

## List Access

List credentials that currently have access to the active wallet.

```swift theme={null}
let credentials = try await oms.wallet.listAccess()

for credential in credentials {
    print(credential.credentialId, credential.expiresAt, credential.isCaller)
}
```

**Parameters**

Takes no parameters.

**Returns**

Returns `[CredentialInfo]`.

## List Access Pages

Use `listAccessPages` when your UI should render credential access one page at a time.

```swift theme={null}
for try await page in oms.wallet.listAccessPages(pageSize: 25) {
    for credential in page.credentials {
        print(credential.credentialId, credential.isCaller)
    }
}
```

**Parameters**

| Parameter  | Type      | Description                                          |
| ---------- | --------- | ---------------------------------------------------- |
| `pageSize` | `UInt32?` | Optional page size used for each Wallet API request. |

**Returns**

Returns `ListAccessPages`, an async sequence of `ListAccessResponse` values.

## List Access Page

Fetch one credential-access page with an optional cursor.

```swift theme={null}
let page = try await oms.wallet.listAccessPage(pageSize: 25)
let nextCursor = page.page?.cursor
```

**Parameters**

| Parameter  | Type      | Description                                  |
| ---------- | --------- | -------------------------------------------- |
| `pageSize` | `UInt32?` | Optional page size for this request.         |
| `cursor`   | `String?` | Optional cursor returned by a previous page. |

**Returns**

Returns `ListAccessResponse`.

## Revoke Access

Revoke another credential's access to the active wallet.

```swift theme={null}
try await oms.wallet.revokeAccess(targetCredentialId: "credential-id")
```

**Parameters**

| Parameter            | Type     | Description                               |
| -------------------- | -------- | ----------------------------------------- |
| `targetCredentialId` | `String` | Credential ID returned by `listAccess()`. |

**Returns**

Returns `Void`.

## Sign Out

```swift theme={null}
try oms.wallet.signOut()
```

Signing out clears the keychain session, wallet identifiers, verifier state, OIDC redirect state, and session signer.

**Parameters**

Takes no parameters.

**Returns**

Returns `Void`.
