1.4.0: Improve Auth Integration
iOS SDK 1.4.0 introduces a more robust Auth Integration API to keep the SDK user state in sync with your app user lifecycle.
-
NEW: Introduce
VitalClient.identifyExternalUser(_:authenticate:)
.-
Identify your user to the SDK, using their unique ID in your system.
-
Identify them after your app's user sign-in and sign-up journeys. Identify them also regularly on app launch.
-
Only when the SDK detects a change in the supplied unique ID, it then performs the SDK sign-in procedure, assisted by the
authenticate
async closure you supplied.
-
-
CHANGED: The following APIs are deprecated:
VitalClient.signIn(withRawToken:configuration:)
VitalClient.configure(...)
VitalClient.setUserId(...)
- Action: Please migrate to the new
identifyExternalUser
API.
-
FIXED:
VitalClient.status
andVitalClient.signIn
could falsely report signed-in after app reinstallation, despite the backing Keychain Item having been purged by the system.
Migrating to identifyExternalUser
While the deprecated VitalClient.signIn
, VitalClient.configure
and VitalClient.setUserId
API would continue to work in 1.4.0 and future releases, we recommend you adopting the new identifyExternalUser
API as soon as you can.
In all places where you currently use VitalClient.signIn
— for customers using Vital Sign-In Token:
let myUserId = "Your User ID"
let expectedVitalUserId = "The Vital User ID associated with {myUserId}"
let myAPIClient: MyAPIClient
// Check if the current Vital SDK user matches our expectation.
if VitalClient.currentUserId != expectedVitalUserId {
// If not, sign them out first.
await VitalClient.signOut()
}
// If we have not signed in with the Vital SDK
if VitalClient.status.contains(.signedIn) == false {
// Ask backend for a Vital Sign-In Token
let response = try await myAPIClient.fetchVitalSignInToken(for: myUserId)
// Pass on the Sign-In Token to the Vital SDK.
try await VitalClient.signIn(withRawToken: response.token)
}
or VitalClient.configure
and VitalClient.setUserId
— for customers using Vital API Key:
VitalClient.configure(apiKey: "...", environment: .sandbox(.us))
VitalClient.setUserId("...")
You can replace it directly with identifyExternalUser
:
let myUserId = "Your User ID"
let myAPIClient: MyAPIClient
try await VitalClient.identifyExternalUser(
myUserId,
authenticate: { myUserId in
// [Vital Sign-In Token]
// Ask backend for a Vital Sign-In Token
let response = try await myAPIClient.fetchVitalSignInToken(for: myUserId)
// Pass on the Sign-In Token to the Vital SDK.
return .signInToken(rawToken: response.token)
// [Vital API Key]
return .apiKey(key: "...", userId: "...", .sandbox(.us))
}
)
You must ensure that myUserId
is a stable identifier that uniquely represents your user. If it changes to a new ID, the SDK assumes your app has switched to a different user, and so it will sign-out and reset all states before signing-in using the new ID.
Make sure that you do call identifyExternalUser
in these moments:
- On or after app launch
- After your user has gone through your sign-in journey (if applicable)
- After your user has gone through your sign-up journey (if applicable)
What happens when my user upgrades to an app release that uses identifyExternalUser
for the first time?
When your app user upgrades from an app release using signIn
to an app release using identifyExternalUser
, they would neither be signed-out nor have their Health SDK sync state cleared.
identifyExternalUser
understands the upgrade scenario, and would seamlessly transition behind the scenes as long as the Sign-In Token does refer to the exact same signed-in Vital User prior to the app upgrade.
What's Changed
- DEV-114: error_details in Sync Progress Log by @andersio in #264
- DEV-114: Add a CoreSDKStateView component as well by @andersio in #265
- DEV-114: Show error cause in sync attempt disclosure by @andersio in #266
- DEV-117: Introduce identifyExternalUser and deprecate signIn by @andersio in #267
- DEV-117: Overhaul SDK startup state storage & Fix inconsistencies caused by dangling keychain items post app reinstallation by @andersio in #268
- Release 1.4.0-beta.1 by @andersio in #270
- Ensure SDK automatic configuration did happen before fetching currentUserId by @andersio in #271
- Release 1.4.0-beta.2 by @andersio in #272
- DEV-117: Detect another case of dangling keychain items post app reinstallation by @andersio in #273
- Release 1.4.0-beta.3 by @andersio in #274
- Release 1.4.0 by @andersio in #275
Full Changelog: 1.3.2...1.4.0