Namespaces
ovok.auth
Sign in, register, manage passwords and sessions, and delete an account.
- Stable unknown
- Release candidate since 0.4.49-rc.4
- Development since 0.4.49-dev.517+4645a0a
Sign-in, registration, password and server-side session calls for a patient or practitioner app. These need a client created without clientSecret; a machine client throws OvokConfigError. Sign-in stores the session through the client's storage.
Sign a user in
const result = await ovok.auth.login({ profileType: 'Practitioner', email, password });
if (result.status === 'mfa-required') {
await ovok.auth.verifyMfa(result.challenge, codeFromAuthenticatorApp);
}profileTypeisPatient,PractitionerorRelatedPerson.loginreturns{ status: 'signed-in', session }or{ status: 'mfa-required', challenge }. Pass the challenge back toverifyMfa.- Tokens come from a PKCE exchange handled for you. The tenant comes from the client's
tenantCode. ovok.auth.current()returns the current session, ornullwhen signed out.ovok.auth.me()fetches the profile.
Register
const result = await ovok.auth.register({
email, password, passwordConfirm: password, name: 'Ada', surname: 'Lovelace',
});
if (result.status === 'clinician-invite') {
// no session was issued; the person must accept a clinician invitation
}
await ovok.auth.registerPractitioner({ email, password, passwordConfirm: password, name, surname });registercreates a patient.registerPractitionercreates a practitioner and returns theSession.- A password and confirmation that differ throw
OvokValidationErrorbefore any request.
Social sign-in
const session = await ovok.auth.socialLogin('google', googleCredential);- Providers are
appleandgoogle. The credential comes from the provider's own SDK. - Needs
clientIdin the client config; without it the call throwsOvokConfigError.
Continue a sign-in made elsewhere
const session = await ovok.auth.adoptSession({
accessToken: earlier.accessToken,
refreshToken: earlier.refreshToken || null,
profile: { reference: earlier.profile.reference, display: earlier.profile.display },
});- Use it to carry a session saved by another client, such as the legacy
OvokClient, into this one. Do not write the session into storage yourself: the storage key and shape belong to the SDK. - It begins the session as a login does: the session is stored, announced to
ovok.session.onChangelisteners, used on the next request and refreshed withrefreshToken. accessTokenand aprofile.referencesuch asPatient/123are required.refreshToken,expiresIn(seconds),projectand thedisplaynames are optional.- Omit
expiresInwhen the token's age is unknown: the first request then refreshes the session. Without arefreshTokenthe token is used until the server refuses it. - It replaces any current session. A missing or malformed field throws
OvokValidationErrornaming the field, and nothing is stored.
Passwords and account deletion
await ovok.auth.changePassword({ oldPassword, newPassword });
await ovok.auth.resetPassword({ email });
await ovok.auth.completePasswordReset(body); // body from the reset email's link
await ovok.auth.deleteAccount(request);changePasswordsends only the old and new password. Check any confirmation field in your app.resetPasswordandcompletePasswordResetneed no signed-in user.deleteAccountschedules the deletion; the user stays signed in until then.
Sessions and sign-out
const sessions = await ovok.auth.sessions.list();
await ovok.auth.sessions.revoke('current');
await ovok.auth.logout();logoutalways clears the local session, even when the server cannot be reached.- Revoking
'current'also ends the session on this device.
Reference
- auth API reference: every method and type.
- ovok.session: saved accounts and account switching.
- Sign users in
- Errors and retries
Last updated on