Authentication
Authenticate the patient with the Nabla SDK
Once a Patient is authenticated in your app, you need to authenticate them on Nabla SDK so that they can securely access their conversations.
You already passed a provideAuthTokens
function during the init process. This function will be called when the Nabla SDK needs to authenticate the Patient. It should return an accessToken
and a refreshToken
from your backend. See server side documentation for more details.
You need to call setCurrentUserOrThrow
on the NablaClient
, which you need to call with a stable patient id, as long as the patient didn't change (it will be passed as parameter to the provideAuthTokens
function).
If you want to change patient, you need to call clearCurrentUser
, as it will clear all data related to the previous patient. Then you will be able to call setCurrentUserOrThrow
with the new patient id.
Otherwise, setCurrentUserOrThrow
will throw a CurrentUserAlreadySetError
Error.
Note that the
provideAuthTokens
will be called only when the SDK needs to identify the patient, it won't be instantaneously called after callingsetCurrentUserOrThrow
.
NablaClient.getInstance().setCurrentUserOrThrow(userId);
Make sure you call
setCurrentUserOrThrow
at least once before calling any other method of the SDK, otherwise anUserIdNotSet
Error will be returned.
Updated 6 months ago