# Logging users out

`logOut()` ends the authenticated session: it clears the access token and session state from the Keychain and tears down the embedded wallet. After it completes the SDK returns to `OFEmbeddedState.unauthenticated`, and the user must authenticate again to access protected resources.

It takes no parameters, returns nothing, and is `async throws` (a completion-handler variant also exists).

## Usage

```swift
import SwiftUI
import OpenfortSwift

struct LogoutButton: View {
    @State private var status = ""

    var body: some View {
        VStack {
            Button("Log out") {
                Task { await logOut() }
            }
            Text(status).font(.footnote)
        }
    }

    func logOut() async {
        do {
            try await OFSDK.shared.logOut()
            status = "Signed out."
            // Route back to your sign-in screen here.
        } catch {
            status = "Error logging out: \(error.localizedDescription)"
        }
    }
}
```

:::tip
Drive your UI from the wallet state rather than from the result of `logOut()` directly. Subscribe to [`embeddedStatePublisher`](/docs/products/embedded-wallet/swift/wallet/state) and show your sign-in screen whenever the state is `.unauthenticated` — this keeps the UI correct no matter how the session ends (manual logout, expiry, or error).
:::

:::warning
For a guest user, logging out **permanently discards** the guest wallet and its assets, because guest accounts aren't recoverable. Prompt guests to [upgrade to a permanent account](/docs/products/embedded-wallet/swift/auth/guest) before signing them out.
:::

## Related

* [User session & access tokens](/docs/products/embedded-wallet/swift/auth/user-session)
* [Embedded wallet state](/docs/products/embedded-wallet/swift/wallet/state)
