FibriCheck
Search…
Examples
This page contains some examples to get you started on using the SDK. For completeness, every example includes the creation and authentication of the SDK. This is of course not necessary and should be

First time authentication to save token/tokenSecret

You can use your email/password combination initially to retrieve an OAuth1 token/secret combination which you can use on to reauthenticate when reloading the application. In this example @react-native-async-storage/async-storage is used, but you can use any persistent storage system.
1
import AsyncStorage from '@react-native-async-storage/async-storage';
2
3
(async () => {
4
const sdk = client({
5
consumerKey: '',
6
consumerSecret: '',
7
});
8
9
const tokenData = await sdk.authenticate({
10
email: '',
11
password: '',
12
});
13
14
AsyncStorage.setItem('tokenData', JSON.stringify(tokenData));
15
})();
Copied!
Afterwards you can use the stored tokenData to authenticate.
1
import AsyncStorage from '@react-native-async-storage/async-storage';
2
(async () => {
3
const tokenDataString = await AsyncStorage.getItem('tokenData');
4
const tokenData = JSON.parse(tokenDataString);
5
6
await sdk.authenticate({
7
token: tokenData.key,
8
tokenSecret: tokenData.secret,
9
});
10
})();
Copied!

Perform a measurement with the Camera SDK component

You can use the RNFibriCheckView exported from the @fibricheck/react-native-camera-sdk package to perform a measurement and hook up sdk.postMeasurement to post the data returned from the camera to the backend in the onMeasurementProcessed event.
1
import client from '@fibricheck/javascript-sdk';
2
import { RNFibriCheckView } from '@fibricheck/react-native-camera-sdk';
3
import { useEffect } from 'react';
4
5
const sdk = client({
6
consumerKey: '',
7
consumerSecret: '',
8
});
9
10
await sdk.authenticate({
11
token: '',
12
tokenSecret: '',
13
});
14
15
const App = () => {
16
return (
17
<RNFibriCheckView
18
onHeartBeat={(heartRate) => {
19
console.log('heartRate', heartRate);
20
}}
21
onTimeRemaining={(seconds) => {
22
console.log('onTimeRemaining', seconds);
23
}}
24
onMeasurementProcessed={async (cameraData) => {
25
console.log('onMeasurementProcessed', cameraData);
26
const measurement = await sdk.postMeasurement(cameraData);
27
console.log('measurement', measurement);
28
}}
29
onFingerDetected={() => {
30
console.log('finger detected');
31
}}
32
/>
33
);
34
};
Copied!

Register a new user

The following snippet shows how you can register a new user. You do not need authentication for registration.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
const user = await sdk.register({
9
firstName: 'John',
10
lastName: 'Doe',
11
12
password: 'Strong!987',
13
phoneNumber: '000000',
14
birthDay: '1970/01/01',
15
gender: 0, // 0 = Not known; 1 = Male; 2 = Female; 9 = Not applicable
16
country: 'JO', // or 'AE'
17
language: 'AR',
18
});
Copied!

Check for updated legal documents

When you use the authentication function, the second parameter should be a callback function (this can also be an arrow function). This function will be called when legal documents have been updated in the FibriCheck cloud and the end-user needs to reapprove these. Example showing how to hook changes to legal documents change with your application and calling the giveConsent function with the document after the user has approved these.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate(
9
{
10
password: '',
11
username: '',
12
},
13
function onConsentNeeded(legalDocumentsUpdated) {
14
/* Will return an array of objects with a key, version and url.
15
* ie.
16
* [{
17
* key: 'privacyPolicy',
18
* version: '1.5.0',
19
* url: 'https://fibricheck.com/privacyPolicy/150'
20
* }]
21
*/
22
23
legalDocumentsUpdated.forEach((document) => {
24
// 1. Request approval from the user
25
26
// 2. Pass the document back to the sdk
27
sdk.giveConsent(document);
28
});
29
},
30
);
Copied!

Fetch a measurement

Use the sdk.getMeasurement function to get a single measurement based on a id. Only measurements for the currently authenticated user can be requested.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate({
9
token: '',
10
tokenSecret: '',
11
});
12
13
const measurementId = '0000';
14
const measurement = await sdk.getMeasurement(measurementId);
Copied!

Fetching all your measurements

Using sdk.getMeasurements will return a paginated result with all measurements for the currently authenticated user. You can find the measurements under the data property. You can also use the next and previous functions present on the result to navigate through the user's measurents.
1
import client from '@fibricheck/javascript-sdk';
2
3
const sdk = client({
4
consumerKey: '',
5
consumerSecret: '',
6
});
7
8
await sdk.authenticate({
9
token: '',
10
tokenSecret: '',
11
});
12
13
// Returns the first 20 measurements
14
const measurements = await sdk.getMeasurements();
15
16
// Returns the next 20 measurements
17
const nextMeasurements = await measurements.next();
Copied!

Request a measurement report and render the PDF

The sdk.getReportUrl accepts a measurementId and will handle creation / fetching of the report. This function works great in combination with react-native-pdf or react-native-share
  • first time calling this function for a measurement, it will take a little longer as the cloud service will render the report. Once it is ready (~5s) the url where you can fetch it will be returned
  • subsequent calls will be much faster, as the report is already rendered and the url will be returned almost instantly.
1
import client from '@fibricheck/javascript-sdk';
2
import Pdf from 'react-native-pdf';
3
4
const sdk = client({
5
consumerKey: '',
6
consumerSecret: '',
7
});
8
9
await sdk.authenticate({
10
token: '',
11
tokenSecret: '',
12
});
13
14
const measurementId = '0000';
15
16
const App = () => {
17
const [uri, setUri] = useState();
18
19
useEffect(() => {
20
(async () => {
21
const uri = await sdk.getReportUrl(measurementId);
22
setUri(uri);
23
})();
24
}, []);
25
26
return (
27
<Pdf
28
source={{
29
uri,
30
}}
31
/>
32
);
33
};
Copied!
Last modified 1mo ago