> ## Documentation Index
> Fetch the complete documentation index at: https://developer.suki.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication Hook

> Sign users in, register accounts, and manage tokens with `useAuth` in the Headless Web SDK

Quick summary

The `useAuth` hook manages user identity in the Suki Headless Web SDK. It gives your component the ability to **sign** users in, **register** new accounts, and **handle security tokens** automatically.

The hook returns status flags (`isLoggedIn`, `isPending`, `error`) and methods (`login()`, `registerUser()`) that you can use to authenticate users and manage their access to Suki services.

Last updated:
October 2026

The **`useAuth`** hook allows you to manage user identity in the Suki Headless Web SDK. It exposes sign-in and registration methods, token updates, and status flags so your UI can react to authentication without wiring a low-level client through props.

In React, think of a hook as a plugin that gives your component specific abilities. In this case, `useAuth` gives your component the ability to **sign** users in,
**register** new accounts, and **handle security tokens** automatically.

## Configuration

The **`useAuth`** hook must run under **`PlatformClientProvider`** (with a shared **`PlatformClient`** at the app root). Refer to [Platform client and provider](https://developer.suki.ai/headless-web-sdk/api-reference/platform-client.md) for more information.

You also need a **`partnerId`** and **`partnerToken`**:

* **`partnerId`:** The unique ID you receive when you onboard with Suki.
* **`partnerToken`:** A JWT issued by your identity provider after the user signs in. Suki does not issue this token. See [Partner authentication](https://developer.suki.ai/documentation/how-to/partner-authentication.md).

> [!NOTE]
>
> If you do not have a **`partnerId`**, refer to [Partner onboarding](https://developer.suki.ai/documentation/get-started/partner-onboarding.md). For how to issue and pass **`partnerToken`**, see [Partner authentication](https://developer.suki.ai/documentation/how-to/partner-authentication.md).

### Common use cases

**1. Authenticate Users**

Use **`login()`** when your application manages sign-in explicitly. Alternatively, enable **`loginOnMount`** to automatically attempt sign-in when the component mounts.

Use the returned authentication state values to manage UI and downstream workflows:

* **`isLoggedIn`** to determine whether the user is authenticated.
* **`isPending`** to display loading or disabled states during sign-in.
* **`data.accessToken`** to access the authenticated session token for subsequent API calls or hooks.

**2. Register New Users**

Use **`registerUser()`** to implement an explicit user registration flow.

To automatically register users who do not already have an account, enable **`autoRegister`**. When **`autoRegister`** is set to `true`, you must also provide the following configuration values:

* **`providerOrgId`**.
* **`providerName`**.
* **`providerSpecialty`**.

For configuration details, refer to [Configuration](#use-auth-hook-configuration) below.

**3. Refresh Partner Authentication Tokens**

Call **`updatePartnerToken()`** whenever your host application issues a new **`partnerToken`**.

Refreshing the token ensures that active sessions remain authenticated and prevents session expiration during long-running workflows. For an implementation example, refer to [Code example](#code-example) below.

**4. Handle Authentication and Registration Errors**

Use **`error`** to inspect authentication and registration failures and implement retry or user-facing error handling logic.

For supported error codes and handling guidance, refer to [Error handling](https://developer.suki.ai/headless-web-sdk/guides/error-handling.md).

> [!NOTE]
>
> **Important:**
>
> When **`autoRegister`** is `true`, **`providerOrgId`**, **`providerName`**, and **`providerSpecialty`** are required on the hook params so auto-registration can succeed.

## useAuth hook

### Usage

Pass a configuration object with **`partnerId`**, **`partnerToken`**, and optional fields (`providerId`, **`autoRegister`**, **`loginOnMount`**, and provider metadata when auto-registration is on).

```tsx theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
const {
  data,
  error,
  isPending,
  isLoggedIn,
  login,
  registerUser,
  updatePartnerToken,
} = useAuth({
  partnerId, // Required
  partnerToken, // Required
  providerId, // Optional
  autoRegister, // Optional
  loginOnMount, // Optional
});
```

### Returns

The hook returns status fields and actions whose shapes are documented under [What you get](#what-you-get) (`isLoggedIn`, `isPending`, `data`, `error`, and `login()`, `registerUser()`, `updatePartnerToken()`).

### How the hook works

![Flowchart: Configure useAuth hook, Mounted?, Call login automatically, Manual login, Authentication status, User authenticated, Use Suki Headless Web SDK.](https://mintcdn.com/suki-1e08f176/eryJVVKcBRotEMfQ/documentation/assets/diagrams/headless-web-sdk-guides-hooks-auth-hook-1-light.svg?fit=max\&auto=format\&n=eryJVVKcBRotEMfQ\&q=85\&s=0916eddd63a7e6ab06bbb0c42780165a)

```mermaid actions={false} theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
flowchart TD
    A[Configure useAuth hook] --> B{Mounted?}
    B -->|yes| C[Call login automatically]
    B -->|no| D[Manual login]
    C --> E{Authentication status}
    D --> E
    E --> J[User authenticated]
    J --> L[Use Suki Headless Web SDK]

    style A fill:#FFF394,stroke:#D4A017,color:#000000
    style J fill:#FFF394,stroke:#D4A017,color:#000000
    style L fill:#FFF394,stroke:#D4A017,color:#000000
```

### Configuration

These are the settings you provide to set up the **auth** hook for Headless Web SDK in your application.

**partnerId** `string` *required*

The unique ID you receive when you first onboard with Suki.

**partnerToken** `string` *required*

JWT issued by your identity provider after the user signs in. Suki does not issue this token. See [Partner authentication](https://developer.suki.ai/documentation/how-to/partner-authentication.md).

**providerId** `string`

**Optional**: The unique ID of the provider in your EHR system.

**autoRegister** `boolean`

**Optional**: If true, users will be automatically registered if they don't have an account yet. This saves you from building a separate registration flow. Default is `True`.

**loginOnMount** `boolean`

**Optional**: If true, the hook attempts to sign the user in as soon as the component loads (mounts). Default is `True`.

**providerOrgId** `string`

The unique ID of the organization in the Suki partner system to which the provider belongs.

This is required for auto-registration to work. If your `autoRegister` is set to `true`, you must provide this value.

**providerName** `string`

The full name of the provider, including first name, middle name (if applicable), and last name separated by spaces.

This is required for auto-registration to work. If your `autoRegister` is set to `true`, you must provide this value.

**providerSpecialty** `string`

The medical specialty of the provider, which helps tailor the SDK's functionality to specific clinical contexts.

This is required for auto-registration to work. If your `autoRegister` is set to `true`, you must provide this value.

```tsx theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
type UseAuthParams = {
  partnerId: string; // Required
  partnerToken: string; // Required
  autoRegister?: true; // This is a boolean value, Default is true
  loginOnMount?: boolean; // Optional
  providerId?: string; // Optional
  providerName: string; // Required for auto-registration to work. If your `autoRegister` is set to `true`, you must provide this value.
  providerOrgId: string; // Required for auto-registration to work. If your `autoRegister` is set to `true`, you must provide this value.
  providerSpecialty?: string; // Required for auto-registration to work. If your `autoRegister` is set to `true`, you must provide this value.
} | {
  partnerId: string; // Required
  partnerToken: string; // Required
  autoRegister?: false; // Default is false
  loginOnMount?: boolean; // Optional
  providerId?: string; // Optional
}
```

## What you get

The hook returns everything you need to track the current status and take action.

### State

Use these values to update your UI (e.g., show a spinner while loading).

**isLoggedIn** `boolean`

A boolean value that indicates whether the user is currently logged in. If `true`, the user is logged in and can use the Suki Headless Web SDK.

**isPending** `boolean`

A boolean value that indicates whether the authentication process is currently in progress (e.g., logging in or registering). If `true`, the hook is working and you can show a spinner to the user.

**data.accessToken** `string`

The active Suki session token. This is the token that is used to authenticate the user with the Suki Headless Web SDK.

**error** `PlatformError`

An error object that contains details if something goes wrong while authenticating the user. Refer to the
[Error handling](https://developer.suki.ai/headless-web-sdk/guides/error-handling.md) to check the possible error codes.

### Actions

Call these functions to perform tasks.

**login()** ` function: () =\> Promise\<LoginResponse\>`

A **function** to start the login process for the user in your application. This function returns a promise that resolves to a `LoginResponse` object.

#### Login Response Example

```tsx theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
type LoginResponse = {
suki_token: string;
jwt_bearer: string
}
```

**registerUser** ` function: (params: RegistrationRequest) =\> Promise\<RegistrationResponse\>`

A **function** to start the registration process for a new user manually (using the provided partner credentials). This function returns a promise that resolves to a `RegistrationResponse` object.

#### Registration Response Example

```tsx theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
type RegistrationResponse = Record<string, never>
```

> [!NOTE]
>
> Success results in an empty object. This means the user is registered successfully and you can now sign them in using the `login` function.

**updatePartnerToken** ` function: (partnerToken: string) =\> Promise\<UpdatePartnerTokenResponse\>`

A **function** to update the `partnerToken` for the user. This function returns a promise that resolves to a `UpdatePartnerTokenResponse` object.

#### Update Partner Token Response Example

```tsx theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
type UpdatePartnerTokenResponse = {
suki_token: string;
jwt_bearer: string
}
```

## Code example

Security tokens often expire and refresh while a user is working. If your application refreshes its token, you must tell the Suki Headless Web SDK so the user's voice session isn't interrupted.

You use `updatePartnerToken` to handle this seamlessly.

```tsx React expandable theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
import { useEffect } from 'react';
import { useAuth } from '@suki-sdk/platform-react';

export const SukiEmbed = ({ currentPartnerToken, partnerId }) => {
  // Initialize the hook
  const { updatePartnerToken, isLoggedIn, error } = useAuth({
    partnerId, // Required
    partnerToken: currentPartnerToken, // Required, The initial token
    loginOnMount: true,                // Optional, Sign in automatically
  });

  // Listen for token changes from your parent app
  useEffect(() => {
    // If we are logged in and the parent app gives us a new token...
    if (isLoggedIn && currentPartnerToken) {
      // ...send it to Suki immediately.
      updatePartnerToken(currentPartnerToken)
        .catch((err) => console.error('Failed to update token:', err));
    }
  }, [currentPartnerToken, isLoggedIn, updatePartnerToken]);

  if (error) {
    return <div>Error signing in: {error.message}</div>;
  }

  return <div>Suki Assistant is ready</div>;
};
```

> [!TIP]
>
> Using `updatePartnerToken` is better than unmounting and remounting the component, as it keeps the user's connection to the Suki Headless Web SDK active and prevents dropped audio.

## Next steps

&#x20;**[Ambient hook](https://developer.suki.ai/headless-web-sdk/guides/hooks/ambient-hook.md)** - Guide to learn more about how to use it to start a voice session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.