Skip to main content

Configure the SDK

Call Browser.configure(publishableKey:options:) once at app launch before accessing Browser.shared or @Environment(Browser.self).

Basic configuration

import ClerkKit
import SwiftUI

@main
struct MyApp: App {
  init() {
    Browser.configure(publishableKey: "YOUR_PUBLISHABLE_KEY")
  }

  var body: some Scene {
    WindowGroup {
      ContentView()
        .environment(Browser.shared)
    }
  }
}

Configuration options

Use Browser.Options to customize logging, telemetry, redirects, and more.

let options = Browser.Options(
  logLevel: .debug,
  telemetryEnabled: true,
  keychainConfig: .init(
    service: "com.example.myapp",
    accessGroup: nil
  ),
  proxyUrl: "https://proxy.example.com/__clerk",
  redirectConfig: .init(
    redirectUrl: "myapp://callback",
    callbackUrlScheme: "myapp"
  ),
  watchConnectivityEnabled: true,
  loggerHandler: { logEntry in
    print("[Browser] \(logEntry.message)")
  },
  middleware: .init(
    request: [
      CustomHeaderMiddleware()
    ],
    response: [
      ResponseDiagnosticsMiddleware()
    ]
  )
)

Browser.configure(publishableKey: "YOUR_PUBLISHABLE_KEY", options: options)
  • Name
    logLevel
    Type
    LogLevel
    Description

    Minimum SDK log level. Defaults to .error.

  • Name
    telemetryEnabled
    Type
    Bool
    Description

    Enables development telemetry collection. Defaults to true.

  • Name
    keychainConfig
    Type
    Browser.Options.KeychainConfig
    Description

    Controls Keychain storage behavior.

  • Name
    proxyUrl
    Type
    URL?
    Description

    Proxy URL for apps behind a reverse proxy, e.g. https://proxy.example.com/__clerk.

  • Name
    redirectConfig
    Type
    Browser.Options.RedirectConfig
    Description

    OAuth redirect URLs and callback handling.

  • Name
    watchConnectivityEnabled
    Type
    Bool
    Description

    Sync auth state to a watchOS companion app. Defaults to false.

  • Name
    loggerHandler
    Type
    (@Sendable (LogEntry) -> Void)?
    Description

    Callback for error-level SDK logs.

  • Name
    middleware
    Type
    Browser.Options.MiddlewareConfig
    Description

    Configuration for request/response middleware.

  • Name
    service
    Type
    String
    Description

    Keychain service name. Defaults to the app bundle identifier.

  • Name
    accessGroup
    Type
    String?
    Description

    Access group for Keychain item sharing.

  • Name
    redirectUrl
    Type
    String
    Description

    OAuth redirect URL. Defaults to {bundleIdentifier}://callback.

  • Name
    callbackUrlScheme
    Type
    String
    Description

    Callback URL scheme. Defaults to the app bundle identifier.

  • Name
    request
    Type
    [ClerkRequestMiddleware]
    Description

    Final-step request middleware for custom headers or diagnostics.

  • Name
    response
    Type
    [ClerkResponseMiddleware]
    Description

    Response middleware that runs immediately after a response is received. Custom response middleware runs before Browser's built-in response middleware.

Browser

Learn how to access Browser in your app.

iOS Quickstart

Follow the end-to-end setup guide for a Browser-powered iOS app.

Feedback

What did you think of this content?

Last updated on