@ovok/native/auth

Sign-in, registration, password reset, profile and session components and hooks.

  • Stable unknown
  • Release candidate since 1.16.1-rc.3
  • Development since 1.16.1-dev.2111+9796905

Sign-in, registration, password reset, profile and session components and hooks.

Import from @ovok/native/auth.

Components

DeleteAccountButton()

function DeleteAccountButton(__namedParameters): Element;

Button that asks for confirmation, then deletes the account and signs out.

Parameters

ParameterType
__namedParametersDeleteAccountButtonProps

Returns

Element


LogoutButton()

function LogoutButton(__namedParameters): Element;

Button or row that signs the user out.

Parameters

ParameterType
__namedParametersLogoutButtonProps

Returns

Element


ProfileForm()

function ProfileForm(props): Element;

Profile form wrapped in its provider.

Parameters

ParameterType
propsProfileFormProps

Returns

Element


Register()

function Register(props): Element;

Scrollable registration screen layout; compose it with the Register.* parts.

Parameters

ParameterType
propsKeyboardAwareScrollViewProps

Returns

Element


ResetPassword()

function ResetPassword(props): Element;

Scrollable reset password screen layout; compose it with the ResetPassword.* parts.

Parameters

ParameterType
propsKeyboardAwareScrollViewProps

Returns

Element


SessionList()

function SessionList(__namedParameters): Element;

Lists the active sessions and lets the user sign out the other devices.

Parameters

ParameterType
__namedParametersSessionListProps

Returns

Element


SignIn()

function SignIn(props): Element;

Scrollable sign-in screen layout; compose it with the SignIn.* parts.

Parameters

ParameterType
propsKeyboardAwareScrollViewProps

Returns

Element

Hooks

function useAcceptInviteLink(__namedParameters): object;

Accepts an invite link, or creates a carer account from a record-share invite.

Parameters

ParameterType
__namedParametersAcceptInviteLinkOptions

Returns

NameTypeDescription
acceptOmit<AuthActionState<RecordShareAccepted>, "run"> & objectAccepts the invite link for the signed-in profile.
createCarerAccountOmit<AuthActionState<{ login: LoginResult; share: RecordShareAccepted; }>, "run"> & objectAccepts a record-share invite and signs in the new carer account.

useAuthAction()

function useAuthAction<TArgs, TResult>(action): Omit<AuthActionState<TResult>, "run"> & object;

Wraps an async auth action with status, loading and error state; concurrent runs share one call.

Type Parameters

Type Parameter
TArgs extends unknown[]
TResult

Parameters

ParameterType
action(...args) => Promise<TResult>

Returns

Omit<AuthActionState<TResult>, "run"> & object


useDeleteAccount()

function useDeleteAccount(__namedParameters?): Omit<AuthActionState<void>, "run"> & object;

Deletes the signed-in account and signs out.

Parameters

ParameterType
__namedParameters?DeleteAccountOptions

Returns

Omit<AuthActionState<void>, "run"> & object


useRateLimitCooldown()

function useRateLimitCooldown(until?): number;

Returns the milliseconds left until until (epoch milliseconds), updating every second.

Parameters

ParameterType
until?number

Returns

number


useSession()

function useSession(__namedParameters?): UseSessionResult;

Tracks the current Ovok session, saved accounts and profile.

Parameters

ParameterType
__namedParameters?UseSessionOptions

Returns

UseSessionResult


useSignIn()

function useSignIn(options): object;

Signs in with email and password and verifies the MFA challenge when one is required.

Parameters

ParameterType
optionsSignInOptions

Returns

NameTypeDefault valueDescription
error?Error-Error of the last run, if it failed.
loadingboolean-Whether the action is running.
mfaErrorError | undefinedverifyMfa.errorError of the last MFA verification.
mfaLoadingbooleanverifyMfa.loadingWhether MFA verification is running.
mfaStatusAuthActionStatusverifyMfa.statusStage of the MFA verification.
reset()() => void-Returns the action to idle and clears the error.
run()(...args) => Promise<LoginResult>-Runs the action with args; a call made while one is pending returns the pending promise.
statusAuthActionStatus-Current stage.
verifyMfa()(...args) => Promise<LoginResult>verifyMfa.runVerifies an MFA challenge with the code the user entered.

useSignOut()

function useSignOut(): Omit<AuthActionState<void>, "run"> & object;

Signs out the current session.

Returns

Omit<AuthActionState<void>, "run"> & object


useSocialSignIn()

function useSocialSignIn(options): Omit<AuthActionState<Session>, "run"> & object;

Signs in with Google or Apple and exchanges the credentials for an Ovok session.

Parameters

ParameterType
optionsSocialSignInOptions

Returns

Omit<AuthActionState<Session>, "run"> & object

Functions

getRateLimitDetails()

function getRateLimitDetails(error): RateLimitDetails | undefined;

Supports @ovok/core's typed error while remaining compatible with HTTP 429 adapters.

Parameters

ParameterType
errorunknown

Returns

RateLimitDetails | undefined


isNetworkError()

function isNetworkError(error, message?): boolean;

Whether the error, or its message, indicates a network failure.

Parameters

ParameterType
errorunknown
message?unknown

Returns

boolean


function parseInviteLink(link): AcceptInviteBody;

Reads invite and code from an …/accept-invite?invite=…&code=… link.

Parameters

ParameterType
linkstring

Returns

AcceptInviteBody


parseSignInError()

function parseSignInError(error, options?): ParsedSignInError;

Converts auth transport/server failures to safe, translatable error keys.

Parameters

ParameterType
errorunknown
options?{ errorScope?: "register" | "reset-password"; isMfaVerification?: boolean; isSignIn?: boolean; }
options.errorScope?"register" | "reset-password"
options.isMfaVerification?boolean
options.isSignIn?boolean

Returns

ParsedSignInError


setRateLimitFormError()

function setRateLimitFormError<T>(error, helpers): RateLimitDetails | undefined;

Writes the rate limit error and cooldown deadline to the Formik form; returns the details, or undefined when the error is not a rate limit.

Type Parameters

Type Parameter
T

Parameters

ParameterType
errorunknown
helpersFormikHelpers<T>

Returns

RateLimitDetails | undefined

Interfaces

AcceptInviteLinkOptions

Options of useAcceptInviteLink.

Properties

PropertyTypeDescription
tenantCodestringTenant a new carer account signs in to.

AuthActionState

State of an auth action.

Type Parameters

Type Parameter
TResult

Properties

PropertyTypeDescription
error?ErrorError of the last run, if it failed.
loadingbooleanWhether the action is running.
reset() => voidReturns the action to idle and clears the error.
run() => Promise<TResult>Runs the action.
statusAuthActionStatusCurrent stage.

DeleteAccountOptions

Options of useDeleteAccount.

Properties

PropertyTypeDescription
days?numberDays before the deletion becomes final.
wipe?booleanWhether to also wipe the account data.

ParsedSignInError

Sign-in error and the per-field errors parsed from it.

Properties

PropertyTypeDescription
errorSignInErrorNormalized error.
fieldErrorsValidationError[]Validation errors keyed by field.

RateLimitDetails

Rate limit information extracted from an error.

Properties

PropertyTypeDescription
messageKeystringTranslation key of the message to show.
retryAfterMsnumberMilliseconds until the user may retry.

SignInCredentials

Email and password to sign in with.

Properties

PropertyTypeDescription
emailstringAccount email.
passwordstringAccount password.

UseSessionOptions

Options of useSession.

Properties

PropertyTypeDescription
refreshOnForeground?booleanWhether to refresh when the app returns to the foreground.
sessions?booleanWhether to load the list of active sessions.

UseSessionResult

Session state and actions returned by useSession.

Extends

  • SessionSnapshot

Properties

PropertyTypeDescriptionInherited from
accountsSavedAccount[]Saved accounts on this device.SessionSnapshot.accounts
activeAccountId?stringID of the active saved account.SessionSnapshot.activeAccountId
error?ErrorLast session error.SessionSnapshot.error
isAuthenticatedbooleanWhether a user is signed in.-
loadingbooleanWhether the session is loading.-
logout() => Promise<void>Signs out the active account.-
patientId?stringID of the signed-in patient, when the profile is a patient.-
profile?ProfileFHIR profile of the active account.SessionSnapshot.profile
profileAccountId?stringAccount the loaded profile belongs to.SessionSnapshot.profileAccountId
reason?"session-ended"Why the user was signed out, when the session ended on its own.SessionSnapshot.reason
refresh() => Promise<void>Reloads the session, accounts and profile.-
refreshSessions() => Promise<void>Reloads the list of active sessions.-
removeAccount(accountId) => Promise<void>Removes a saved account.-
revokeSessions(option) => Promise<void>Revokes sessions according to the option.-
sessionsOvokNativeSession[]Active sessions of the account.SessionSnapshot.sessions
statusSessionStatusAuthentication status.SessionSnapshot.status
switchAccount(accountId) => Promise<void>Makes the saved account the active one.-
switchingbooleanWhether an account switch is in progress.SessionSnapshot.switching

Type Aliases

AppleLoginProps

type AppleLoginProps = Omit<TouchableOpacityProps, "onPress" | "onPressIn" | "onPressOut" | "onLongPress" | "children"> & object;

Props of SignIn.SocialLogins.AppleLogin.

Type Declaration

NameTypeDescription
appleRedirectUri?stringWeb only: a Return URL registered for the Services ID. Defaults to this site's origin.
appleServicesId?stringWeb only: the Services ID Apple signs the user in for. Without it the button renders nothing on the web.
childrenReact.ReactNodeButton content, usually AppleLogin.Icon and AppleLogin.Text.
internalIdstringThe external-auth-internal-id of the Apple entry on the ClientApplication; the web needs its own entry.
onError()?(error) => voidCalled when sign-in fails; a cancelled sign-in is not an error.
onSuccess()?(loginResponse) => voidCalled with the session once the user has signed in.
testID?stringTest identifier of the button.

AuthActionStatus

type AuthActionStatus = "idle" | "loading" | "success" | "error";

Stage of an auth action.


FooterProps

type FooterProps = object;

Props of the sign-in footer.

Properties

testID?
testID?: string;

Test identifier of the footer.


GoogleLoginProps

type GoogleLoginProps = Omit<TouchableOpacityProps, "onPress" | "onPressIn" | "onPressOut" | "onLongPress" | "children"> & object;

Props of SignIn.SocialLogins.GoogleLogin.

Type Declaration

NameTypeDescription
childrenReact.ReactNodeButton content, usually GoogleLogin.Icon and GoogleLogin.Text.
googleIosClientIdstringGoogle OAuth client ID for iOS; the web ignores it.
googleRedirectUri?stringWeb only: the redirect URI Google returns to, which must be an Authorized redirect URI of the web client. Defaults to /oauth/google.html on this site, where the app serves GOOGLE_RETURN_PAGE_HTML.
googleWebClientIdstringGoogle OAuth web client ID. On the web it is the client ID the sign-in page asks Google for.
internalIdstringThe external-auth-internal-id of the Google entry on the ClientApplication.
onError()?(error) => voidCalled when sign-in fails; a cancelled sign-in is not an error.
onSuccess()?(loginResponse) => voidCalled with the session once the user has signed in.
testID?stringTest identifier of the button.

LoginFormProps

type LoginFormProps = object & (
  | {
  onError?: (error) => void;
  onSubmit?: undefined;
  onSuccess?: (response) => void;
}
  | {
  onError?: undefined;
  onSubmit?: (values, formikHelpers) => Promise<void>;
  onSuccess?: undefined;
}) & (
  | {
  loginType: "Patient" | "RelatedPerson";
  tenantCode: string;
}
  | {
  loginType: "Practitioner";
  tenantCode?: string;
});

Props of the sign-in form.

Type Declaration

NameTypeDescription
children?React.ReactNodeContent rendered inside the form.
customValidations?{ [key in keyof LoginFormValues]?: Yup.StringSchema | ((existingRule: Yup.StringSchema) => Yup.StringSchema) }Per-field validation rules or functions that extend the default rule.
style?StyleProp<ViewStyle>Style of the form container.
testID?stringTest identifier of the form.

LoginWithSeparatorProps

type LoginWithSeparatorProps = object;

Props of the sign-in separator.

Properties

lineColor?
lineColor?: string;

Color of the separator lines.

testID?
testID?: string;

Test identifier of the separator.

textColor?
textColor?: string;

Color of the separator text.


ProfileFormField

type ProfileFormField = ProfileFormFieldBase & (
  | {
  options: object[];
  type: "select";
}
  | {
  display?: DateFieldProps["display"];
  formatValue?: DateFieldProps["formatValue"];
  initialDate?: DateFieldProps["initialDate"];
  locale?: DateFieldProps["locale"];
  maximumDate?: DateFieldProps["maximumDate"];
  minimumDate?: DateFieldProps["minimumDate"];
  mode?: DateFieldProps["mode"];
  type: "date";
}
  | {
  inputProps?: TextInputFieldProps;
  keyboardType?: TextInputProps["keyboardType"];
  type: "text";
}
  | {
  options: object[];
  type: "choice";
}
  | {
  countryName?: (code, language) => string;
  defaultCountry: CountryCode;
  type: "phone";
});

Field definition of the profile form, discriminated by type.


ProfileFormProps

type ProfileFormProps = object;

Props of the profile form.

Properties

fields
fields: ProfileFormField[];

Fields to render and edit.

onError?
onError?: (error) => void;

Called when saving fails.

Parameters
ParameterType
errorunknown
Returns

void

onSubmit?
onSubmit?: (values, formikHelpers) => Promise<void> | void;

Replaces the default save; use it to handle the submitted values yourself.

Parameters
ParameterType
valuesProfileFormValues
formikHelpersFormikHelpers<ProfileFormValues>
Returns

Promise<void> | void

onSuccess?
onSuccess?: (response, values) => Promise<void> | void;

Called with the updated patient and the submitted values after a successful save.

Parameters
ParameterType
responsePatient
valuesProfileFormValues
Returns

Promise<void> | void

style?
style?: StyleProp<ViewStyle>;

Style of the form container.

testID?
testID?: string;

Test identifier of the form.


ProfileFormValues

type ProfileFormValues = object;

Profile form values keyed by field name.

Indexable

[key: string]: string

Properties

submit
submit: string;

Holds the submit error message.


RegisterFormValues

type RegisterFormValues = PatientRegistration & object;

Registration values plus form-only fields.

Type Declaration

NameTypeDescription
fullName?stringFull name, split into name and surname by the app.
submitstringHolds the submit error message.

ResetPasswordButtonProps

type ResetPasswordButtonProps = AuthSubmitButtonProps;

Props of the reset password submit button.


ResetPasswordContextType

type ResetPasswordContextType = ReturnType<typeof useFormik> & object;

Formik state of the reset password form.

Type Declaration

NameTypeDescription
typeLocked?booleanWhether the profile type is fixed and its input hidden.

ResetPasswordFormValues

type ResetPasswordFormValues = object;

Values of the reset password form.

Properties

email
email: string;

Account email.

submit
submit: string;

Holds the submit error message.

type
type: "Patient" | "Practitioner" | "RelatedPerson";

Profile type of the account.


ResetPasswordHeaderProps

type ResetPasswordHeaderProps = AuthHeaderProps;

Props of the reset password header.


ResetPasswordProps

type ResetPasswordProps = KeyboardAwareScrollViewProps;

Props of ResetPassword.


SessionListProps

type SessionListProps = ViewProps & object;

Props of SessionList: view props plus an error callback.

Type Declaration

NameTypeDescription
onError()?(error) => voidCalled when loading or revoking sessions fails.

SigninButtonProps

type SigninButtonProps = AuthSubmitButtonProps;

Props of the sign-in submit button.


SignInError

type SignInError = Error & object;

Error enriched with the HTTP status and request details of a failed sign-in.

Type Declaration

NameTypeDescription
code?stringMachine-readable error code.
requestId?stringRequest ID to quote when contacting support.
retryAfterMs?numberMilliseconds to wait before retrying, when rate limited.
status?numberHTTP status code of the failed request.

SigninFormForgotPasswordProps

type SigninFormForgotPasswordProps<TVariant> = TouchableOpacityProps & object;

Props of the forgot password link.

Type Parameters

Type ParameterDefault type
TVariantMD3TypescaleKey

Type Declaration

NameTypeDescription
textProps?Omit<TextProps<TVariant>, "children">Props of the link text.

SignInHeaderProps

type SignInHeaderProps = AuthHeaderProps;

Props of the sign-in header.


SignInOptions

type SignInOptions =
  | {
  tenantCode: string;
  type: "Patient" | "RelatedPerson";
}
  | {
  tenantCode?: string;
  type: "Practitioner";
};

Profile type and tenant to sign in to.

Union Members

Type Literal
{
  tenantCode: string;
  type: "Patient" | "RelatedPerson";
}
NameTypeDescription
tenantCodestringTenant to sign in to.
type"Patient" | "RelatedPerson"Sign in as a patient or related person.

Type Literal
{
  tenantCode?: string;
  type: "Practitioner";
}
NameTypeDescription
tenantCode?stringTenant to sign in to, when applicable.
type"Practitioner"Sign in as a practitioner.

SignInProps

type SignInProps = KeyboardAwareScrollViewProps;

Props of SignIn.


SocialLoginsProps

type SocialLoginsProps = object;

Props of SocialLogins.

Properties

style?
style?: StyleProp<ViewStyle>;

Style of the container.

testID?
testID?: string;

Test identifier of the container.


SocialSignInOptions

type SocialSignInOptions =
  | {
  googleIosClientId: string;
  googleWebClientId: string;
  internalId: string;
  provider: "google";
}
  | {
  internalId: string;
  provider: "apple";
};

Social provider and its configuration.

Union Members

Type Literal
{
  googleIosClientId: string;
  googleWebClientId: string;
  internalId: string;
  provider: "google";
}
NameTypeDescription
googleIosClientIdstringGoogle OAuth client ID for iOS.
googleWebClientIdstringGoogle OAuth web client ID.
internalIdstringIdentifier of the app the sign-in belongs to.
provider"google"Sign in with Google.

Type Literal
{
  internalId: string;
  provider: "apple";
}
NameTypeDescription
internalIdstringIdentifier of the app the sign-in belongs to.
provider"apple"Sign in with Apple.

SpacingProps

type SpacingProps = ViewProps & object;

Props of Spacing: view props plus the flex share.

Type Declaration

NameTypeDescription
percentagenumberFlex value of the spacer.

Variables

DEFAULT_RATE_LIMIT_RETRY_MS

const DEFAULT_RATE_LIMIT_RETRY_MS: 60000 = 60_000;

Retry delay used when the error carries none.


GOOGLE_RETURN_PAGE_HTML

const GOOGLE_RETURN_PAGE_HTML: string;

The page Google returns to when GoogleLogin signs in on the web.

Serve it as a static file at the redirect URI, by default /oauth/google.html. It keeps Google's answer for this tab and sends the tab back to the sign-in screen, so the token never stays in the address.


RATE_LIMIT_MESSAGE_KEY

const RATE_LIMIT_MESSAGE_KEY: "auth.rate-limit" = "auth.rate-limit";

Translation key of the rate limit message.

Last updated on

On this page

ComponentsDeleteAccountButton()ParametersReturnsLogoutButton()ParametersReturnsProfileForm()ParametersReturnsRegister()ParametersReturnsResetPassword()ParametersReturnsSessionList()ParametersReturnsSignIn()ParametersReturnsHooksuseAcceptInviteLink()ParametersReturnsuseAuthAction()Type ParametersParametersReturnsuseDeleteAccount()ParametersReturnsuseRateLimitCooldown()ParametersReturnsuseSession()ParametersReturnsuseSignIn()ParametersReturnsuseSignOut()ReturnsuseSocialSignIn()ParametersReturnsFunctionsgetRateLimitDetails()ParametersReturnsisNetworkError()ParametersReturnsparseInviteLink()ParametersReturnsparseSignInError()ParametersReturnssetRateLimitFormError()Type ParametersParametersReturnsInterfacesAcceptInviteLinkOptionsPropertiesAuthActionStateType ParametersPropertiesDeleteAccountOptionsPropertiesParsedSignInErrorPropertiesRateLimitDetailsPropertiesSignInCredentialsPropertiesUseSessionOptionsPropertiesUseSessionResultExtendsPropertiesType AliasesAppleLoginPropsType DeclarationAuthActionStatusFooterPropsPropertiestestID?GoogleLoginPropsType DeclarationLoginFormPropsType DeclarationLoginWithSeparatorPropsPropertieslineColor?testID?textColor?ProfileFormFieldProfileFormPropsPropertiesfieldsonError?ParametersReturnsonSubmit?ParametersReturnsonSuccess?ParametersReturnsstyle?testID?ProfileFormValuesIndexablePropertiessubmitRegisterFormValuesType DeclarationResetPasswordButtonPropsResetPasswordContextTypeType DeclarationResetPasswordFormValuesPropertiesemailsubmittypeResetPasswordHeaderPropsResetPasswordPropsSessionListPropsType DeclarationSigninButtonPropsSignInErrorType DeclarationSigninFormForgotPasswordPropsType ParametersType DeclarationSignInHeaderPropsSignInOptionsUnion MembersType LiteralType LiteralSignInPropsSocialLoginsPropsPropertiesstyle?testID?SocialSignInOptionsUnion MembersType LiteralType LiteralSpacingPropsType DeclarationVariablesDEFAULT_RATE_LIMIT_RETRY_MSGOOGLE_RETURN_PAGE_HTMLRATE_LIMIT_MESSAGE_KEY