Skip to main content
Version: iOS-10.0.1

iOS Customer User APIs

Customer user APIs for account signup, login/logout, and account recovery. Access these APIs through vipaso.user.customer.

Authentication

Login

Authenticate an existing customer with phone number and password:

do {
let request = LoginRequest(identifier: phoneNumber, password: password)
try await vipaso.user.customer.login(request: request)
// User successfully logged in
// Authentication state change will be sent via delegate
} catch {
// Handle login error
print("Login failed: \(error.localizedDescription)")
}

Logout

Log out the current customer:

vipaso.user.customer.logout()
// Authentication state change will be sent via delegate

Account Signup

The signup process requires three steps: starting the flow, verifying the phone number, and completing the signup.

1. Start Signup Flow

Begin the signup process with a phone number. This sends an OTP code to the provided number:

do {
let request = StartSignupRequest(phoneNumber: phoneNumber)
let response = try await vipaso.user.customer.startSignupFlow(request: request)
// Save the flowID for the next step
let flowID = response.flowID
} catch {
print("Signup start failed: \(error.localizedDescription)")
}

2. Verify Phone Number

Verify the phone number using the OTP code received via SMS:

do {
let request = VerifyPhoneNumberRequest(flowID: flowID, otp: otp)
let response = try await vipaso.user.customer.verifyPhoneNumber(request: request)
// Phone number verified, save flowID for final step
let verifiedFlowID = response.flowID
} catch {
print("Phone verification failed: \(error.localizedDescription)")
}

3. Complete Signup

Finish the signup by providing user details:

do {
let request = FinishSignupRequest(
flowID: flowID,
password: password,
email: email,
firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber
)
let response = try await vipaso.user.customer.finishSignupFlow(request: request)
// Signup completed successfully
// User is now logged in, authentication state change sent via delegate
} catch {
print("Signup completion failed: \(error.localizedDescription)")
}

Password Recovery

The password recovery process has three steps: starting recovery, sending OTP, and completing the password change.

1. Start Recovery Flow

Begin password recovery with the customer's phone number:

do {
let request = StartRecoveryRequest(phoneNumber: phoneNumber)
let response = try await vipaso.user.customer.startRecoveryFlow(request: request)
// Save the flowID for the next step
let flowID = response.flowID
} catch {
print("Recovery start failed: \(error.localizedDescription)")
}

2. Send Recovery OTP

Submit the OTP code received via SMS:

do {
let request = RecoveryOTPRequest(code: otp, flowID: flowID)
let response = try await vipaso.user.customer.sendRecoveryOTP(request: request)
// Save both settingsFlowID and sessionToken for final step
let settingsFlowID = response.settingsFlowID
let sessionToken = response.sessionToken
} catch {
print("OTP verification failed: \(error.localizedDescription)")
}

3. Complete Password Recovery

Set the new password using the settings flow ID and session token:

do {
let request = FinishRecoveryRequest(
settingsFlowID: settingsFlowID,
sessionToken: sessionToken,
password: newPassword
)
let response = try await vipaso.user.customer.finishRecoveryFlow(request: request)
// Password successfully updated
} catch {
print("Password recovery failed: \(error.localizedDescription)")
}

User Data

Fetch User Details

Get the current customer's profile information:

do {
let response = try await vipaso.user.customer.fetchUser()
let user = response.user
// Access user.id, user.phone, user.firstName, etc.
} catch {
print("Fetch user failed: \(error.localizedDescription)")
}