Quick Summary
The
The hook returns status flags (
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.Overview
TheuseAuth hook is your primary tool for managing user identity in the Suki Headless Web SDK.
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.
Prerequisites
Before you begin, the following guide require apartnerId and partnerToken:
partnerId- The unique ID you receive when you first onboard with SukipartnerToken- The secure access token for the user, generated by your EHR system
If you do not have a
partnerID and partnerToken, refer to the Authentication Guide guide to learn more.How It Works
To use theuseAuth hook, you pass it a configuration object with your partner credentials. It returns a set of data (like isLoggedIn) and methods (like login()) that you can use in your application.
Configuration
These are the settings you provide to set up the auth hook for Headless Web SDK in your application.The unique ID you receive when you first onboard with Suki.
The secure access token for the user, generated by your EHR system.
Optional: The unique ID of the provider in your EHR system.
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.Optional: If true, the hook attempts to sign the user in as soon as the component loads (mounts). Default is
True.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.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.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.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).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.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.The active Suki session token. This is the token that is used to authenticate the user with the Suki Headless Web SDK.
An error object that contains details if something goes wrong while authenticating the user. Refer to the
Error Handling to check the possible error codes.
Actions
Call these functions to perform tasks.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
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
Success results in an empty object. Means, the user is registered successfully and you can now sign them in using the
login function.A function to update the partner token for the user. This function returns a promise that resolves to a
UpdatePartnerTokenResponse object.Update Partner Token Response Example
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 useupdatePartnerToken to handle this seamlessly.
React