Skip to main content
The Dynamic Swift SDK provides email and SMS authentication through OTP (One-Time Password) verification.

Email Authentication

import DynamicSDKSwift

let sdk = DynamicSDK.instance()

// Send OTP to email
await sdk.auth.email.sendOTP(email: "[email protected]")

// Later, verify:
try await sdk.auth.email.verifyOTP(token: "received-otp")

// Resend if needed:
try await sdk.auth.email.resendOTP()

Rate Limits

Email verification is subject to the following rate limits:
  • 3 attempts per 10 minutes per email address
This is in place to protect deliverability of emails and to prevent abuse.

SMS Authentication

import DynamicSDKSwift

let sdk = DynamicSDK.instance()

// Send OTP via SMS
let phoneData = PhoneData(
    dialCode: "+1",
    iso2: "US",
    phone: "5551234567"
)
try await sdk.auth.sms.sendOTP(phoneData: phoneData)

// Later, verify:
try await sdk.auth.sms.verifyOTP(token: "received-otp")

// Resend if needed:
try await sdk.auth.sms.resendOTP()

External JWT Authentication

For apps with existing authentication systems, you can authenticate users with an external JWT:
import DynamicSDKSwift

let sdk = DynamicSDK.instance()

try await sdk.auth.externalAuth.signInWithExternalJwt(
    props: SignInWithExternalJwtParams(jwt: yourJwtToken)
)

Authentication State

import DynamicSDKSwift

let sdk = DynamicSDK.instance()

// Check current user
if let user = sdk.auth.authenticatedUser {
    print("User: \(user.userId)")
}

// Get auth token
if let token = sdk.auth.token {
    print("Token: \(token)")
}

// Listen for changes (Combine)
sdk.auth.authenticatedUserChanges
    .sink { user in
        // Handle user changes
    }
    .store(in: &cancellables)

// Logout
try await sdk.auth.logout()

Built-in UI

The easiest way to add authentication is using the built-in UI which handles all authentication methods:
import DynamicSDKSwift

let sdk = DynamicSDK.instance()
sdk.ui.showAuth()