Swift
public func sendEmailOtp( client: DynamicClient, email: String ) async throws -> OTPVerification
let otpVerification = try await sendEmailOtp( client: dynamicClient, email: "[email protected]" ) // Store for verification step var currentOtpVerification: OTPVerification? currentOtpVerification = otpVerification
public func sendSmsOtp( client: DynamicClient, phoneNumber: String, phoneCountryCode: String, isoCountryCode: String ) async throws -> OTPVerification
let otpVerification = try await sendSmsOtp( client: dynamicClient, phoneNumber: "1234567890", phoneCountryCode: "+1", isoCountryCode: "US" ) // Store for verification step var currentOtpVerification: OTPVerification? currentOtpVerification = otpVerification
public func verifyOtp( otpVerification: OTPVerification, verificationToken: String ) async throws -> SdkUser
guard let otpVerification = currentOtpVerification else { print("No OTP verification in progress") return } do { let authenticatedUser = try await verifyOtp( otpVerification: otpVerification, verificationToken: "123456" ) print("Welcome \(authenticatedUser.email ?? "")") } catch { print("Invalid OTP: \(error)") }
public func verifySmsOtp( otpVerification: OTPVerification, verificationToken: String ) async throws -> SdkUser
guard let otpVerification = currentOtpVerification else { print("No OTP verification in progress") return } do { let authenticatedUser = try await verifySmsOtp( otpVerification: otpVerification, verificationToken: "123456" ) print("Welcome user with phone: \(authenticatedUser.phoneNumber ?? "")") } catch { print("Invalid OTP: \(error)") }
public func logout(client: DynamicClient) async throws
do { try await logout(client: dynamicClient) print("User logged out successfully") } catch { print("Logout failed: \(error)") }
import DynamicSwiftSDK let dynamicClient: DynamicClient let userEmail: String = "[email protected]" // Step 1: Send OTP let otpVerification = try await sendEmailOtp( client: dynamicClient, email: userEmail ) // Step 2: Verify OTP (when user enters code) let otpCode: String = "123456" // User input let authenticatedUser = try await verifyOtp( otpVerification: otpVerification, verificationToken: otpCode ) print("Welcome \(authenticatedUser.email ?? "")")
import DynamicSwiftSDK let dynamicClient: DynamicClient let phoneNumber: String = "1234567890" let phoneCountryCode: String = "+1" let isoCountryCode: String = "US" // Step 1: Send OTP let otpVerification = try await sendSmsOtp( client: dynamicClient, phoneNumber: phoneNumber, phoneCountryCode: phoneCountryCode, isoCountryCode: isoCountryCode ) // Step 2: Verify OTP (when user enters code) let otpCode: String = "123456" // User input let authenticatedUser = try await verifySmsOtp( otpVerification: otpVerification, verificationToken: otpCode ) print("Welcome user with phone: \(authenticatedUser.phoneNumber ?? "")")
Was this page helpful?