Authentication

React Native ==> Session module

Authenticating requests with the Validic API requires a Validic Mobile User to be provisioned and with a Validic Mobile User Token. Further documentation for creating Validic Mobile Users is available in Provisioning and Managing Users .

You will need to provision the user from your server or your mobile app first. And then you will need to start a valid user session in the mobile SDK.

Provisioning a User

It is required to use valid Validic user credentials. The validicUserID, organizationID, and accessToken properties will be sent to the Inform server for validation at the start of any user session. Sessions started with invalid or unknown user credentials (i.e. any credentials not provisioned by the Validic API) will be ended automatically and you will not be able to receive data records from the Inform SDK.

It is recommended to provision the user on your server, the mobile app could then authenticate to the server and retrieve the Validic credentials.

The ValidicCore module stores the active user session and all pending record uploads. This data is persisted between app launches but is deleted if the ValidicCore.endSession function is called.

Start Session

To start a new session, pass valid Validic user credentials to the startSession function.

try {
  const user = {
    userID: 'user123',
    organizationID: 'org123',
    accessToken: 'access123',
  };
  await ValidicCore.startSession(user);
} catch (e) {
  // credentials are empty or missing
  console.log(e);
}

The supplied credentials are validated when the session is started. If invalid credentials are provided, the session will be ended. See Events for listening for the session end event. To change credentials, end the current session and start a new one with the new credentials. See Record Events for listening for the session ending.

await ValidicCore.endSession();
await ValidicCore.startSession(new_user);

When a new session is created, pending record uploads and health subscriptions are deleted. For this reason, a new session should only be started if a session is not already active.

To check if there is an existing session, use getCurrentUser().

const existingUser = await ValidicCore.getCurrentUser();
if (!existingUser) {
  // no existing session - start a new one
}

End Session

An end user's session be ended by calling endSession. This will end the client's persisted User and cancel all pending work in the Validic Mobile SDKs. See Record Events for details on how to listen for User Session events.

ValidicCore.endSession();  

Keep in mind the Important Considerations when ending the user session.