Profile Sync
Pre-populate user data during authentication
When a user authenticates, the SDK can send partner-collected data — profile details, address, insurance, and dependents — alongside the auth.upgrade message. Sunny uses this to pre-populate the user’s account, removing the need for the user to re-enter information they’ve already provided to your application.
How it works
Profile sync data is included in the auth.upgrade WebSocket message that fires when a user authenticates. The backend uses upsert semantics: it only creates or updates records for the fields you provide, and leaves everything else untouched.
Configuration
Pass authUpgradeProfileSync to createSunnyChat. You can provide static data or an async function that resolves the data at authentication time.
Static data
Async provider
Use a function when the data needs to be fetched at authentication time — for example, from your own API:
Returning null from the provider skips profile sync entirely — the user authenticates normally without any pre-populated data.
Data types
All fields in authUpgradeProfileSync are optional. Include only what your application has collected.
User profile
Basic demographic information. All fields are optional; only provided fields are updated.
Address
Mailing address for the user. When provided, address_line_1, city, state, and zip_code are required.
Insurance
Insurance plan records. The partner_plan_id is a UUID that maps to a plan configured in Sunny Central for your partner. Requires partnerIdentifier on the SDK connection.
Dependents
Family members or dependents covered under the user’s insurance. Each dependent can be linked to a specific insurance plan by index.
Relationship codes
The relationship_code field uses Stedi relationship codes:
Linking dependents to insurance plans
The insurance_index field links a dependent to a specific entry in the insurances array (zero-based). If omitted, the dependent is associated with the first insurance plan.
Full example
A complete example syncing all data types with an async provider:
Behavior notes
- Upsert semantics — the backend creates new records or updates existing ones. Existing data not covered by the payload is left unchanged.
- Dependent deduplication — dependents are matched by natural key (first name + last name + date of birth). Sending the same dependent twice updates the existing record rather than creating a duplicate.
- Auth mode compatibility — profile sync works with all authentication modes (token exchange and passwordless).
- Timing — the async provider is called at authentication time, just before the
auth.upgrademessage is sent. This ensures data is as fresh as possible.
Next steps
- Authentication — Configure authentication modes
- Key Concepts — Conversations, events, and state management
- API Reference — REST and WebSocket API schemas