User
Manage user identity within the app. Register a user ID to associate the current device with a known user, unregister on logout, and let users request account deletion. The user ID is persisted in localStorage so it survives page reloads.
Access: startiapp.User
Properties
userId
get userId(): string | nullReturns the currently registered user ID, or null if no user is registered. The value is read from memory first, falling back to localStorage under the key startiapp-clientUserId.
Example:
const id = startiapp.User.userId;
if (id) {
console.log("Logged in as", id);
} else {
console.log("No user registered");
}Methods
registerId(userId): Promise<void>
Registers a user ID for the current device. This associates the device (identified by its installation ID and FCM push token) with your application's user identifier. Call this after the user logs in.
Internally, the method also triggers an External Purchase Custom Link token fetch if the integration is available.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | Your application's unique identifier for the user. |
Returns: Promise<void> —Resolves when the registration has been confirmed by the server.
Throws:
Errorif no FCM token is available (push notifications must be initialized first).Errorif the server returns a non-OK HTTP status.
Example:
try {
await startiapp.User.registerId("user-12345");
console.log("User registered successfully");
} catch (error) {
console.error("Registration failed:", error.message);
}unregisterId(): Promise<void>
Unregisters the current user from the device. Call this when the user logs out. The stored user ID is cleared and the server is notified so the device is no longer associated with any user.
Returns: Promise<void> —Resolves when the server confirms the unregistration.
Throws:
Errorif the server returns a non-OK HTTP status.
Example:
await startiapp.User.unregisterId();
console.log("User logged out");deleteUser(options?): Promise<void>
Requests deletion of the current user's account. A browser confirmation dialog is shown before the request is sent. On success, an alert informs the user that the request has been received.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| options | RequestUserDeletionOptions | No | Override the default prompt and confirmation messages. |
Returns: Promise<void> —Resolves when the deletion request has been submitted to the server.
Throws:
Errorif no user ID is currently registered.Errorif the server returns a non-OK HTTP status.
Example:
// With default messages
await startiapp.User.deleteUser();
// With custom messages
await startiapp.User.deleteUser({
prompt: "Are you sure you want to delete your account?",
confirmation: "Your deletion request has been received. We will follow up shortly.",
});Types
RequestUserDeletionOptions
Options for customizing the deleteUser confirmation dialogs.
interface RequestUserDeletionOptions {
/** Text shown in the confirmation dialog before sending the request. */
prompt?: string;
/** Text shown in the alert after the request succeeds. */
confirmation?: string;
}Storage
Persistent key-value storage and web data management. The Storage module provides two capabilities: app-level key-value storage via Storage.app, and web data clearing via Storage.clearWebData().
Admin API
Server-to-server API for sending push notifications to users and topics. Requires an API key from the starti.app manager.