User and profile
setUser, updateUser, logout, reset, and mutation queue semantics for @motisig/expo-motisig-sdk.
All APIs below are on a MotiSig instance after await motisig.initialize(...).
setUser(id, extras?)
Registers the user with the MotiSig AI client API (POST /users) with platform, timezone (Intl.DateTimeFormat().resolvedOptions().timeZone), and locale. Any fields you pass in extras override those defaults.
- If the server returns 409 Conflict, the SDK treats the user as already registered and continues.
- On success (including the 409 path), the user id is persisted locally (via
@react-native-async-storage/async-storagewhen installed; otherwise in-memory only for the current process). - After the user id is set, the SDK upserts an Expo push subscription (token +
permission+ customer-enabledflag) when an Expo push token is available. See Push notifications. - Switching to a different user id resets
lastSyncedPermissionso the next foreground resume re-evaluates and patches if needed.
setUser runs on the SDK's AsyncQueue relative to other mutations.
await motisig.setUser('user-123');
await motisig.setUser('user-123', {
timezone: 'America/Los_Angeles',
locale: 'en-US',
});updateUser(payload)
Sends PATCH /users/{id} with the fields allowed by the client API:
await motisig.updateUser({
firstName: 'Ada',
lastName: 'Lovelace',
email: 'ada@example.com',
// timezone and locale default to the device values if omitted
});If no user is set, the call throws (No user is set; call setUser first). All user-scoped methods throw on missing user — wrap in try/catch if you want to ignore that case.
logout()
- If both
userIdand a known Expo push token exist, the SDK enqueuesDELETE …/push-subscriptionsfor that pair (best-effort; errors are swallowed). - Clears
userId,lastSyncedPermission, the persisted user id, and the pending click queue + dedupe store. - Does not detach notification listeners or clear the customer push preference. Use
reset()for a full teardown.
await motisig.logout();reset()
Tears down everything in-process:
- Removes notification listeners (
expo-notifications). - Stops the foreground ping interval and
AppStatesubscription. - Clears the event emitter.
- Drops
userId,lastToken,lastSyncedPermission, and the foreground id ring buffer. - Marks the instance uninitialized; you can call
initializeagain afterward.
reset() is synchronous and does not call the server. Combine with logout() if you also want to remove the server-side push subscription.
Mutation queue semantics
Every user-scoped HTTP call is wrapped in mutationQueue.run(async () => { ... }). The queue is a single-threaded promise chain that:
- Captures
userId(and the resolved Expo push token, where applicable) at the moment the closure runs. - Awaits the previous mutation before starting the next.
- Lets exceptions propagate to the caller's
await.
This guarantees that the observable order of writes matches the order of calls, even when individual HTTP requests would otherwise complete out of order.
Related
- Events, tags, attributes, and ping
- Push notifications
MotiSigApiError/MotiSigErrorin the SDKsrc/errors