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 data.

You already pass a SessionTokenProvider 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 with a stable patient id, as long as the patient didn't change (it will be passed as parameter to the SessionTokenProvider).

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 NablaException.AuthenticationCurrentUserAlreadySet exception.

📘

Note that the SessionTokenProvider will be called only when the SDK needs to identify the patient, it won't be instantaneously called after calling setCurrentUserOrThrow.


NablaClient.getInstance().setCurrentUserOrThrow(userId)

⚠️

Make sure you call setCurrentUserOrThrow at least once before calling any other method of the SDK, otherwise a NablaException.Authentication.UserIdNotSet will be returned as Result.