# Enrolment Flow

In order to use our SDK you need an authorization token. Please check our API "[Authorisation](https://docs.uqudo.com/docs/kyc/uqudo-api/authorisation)" in this regard.

Add the following code at the start-up of your application to initialize the SDK:

```javascript
import { 
  DocumentBuilder,
  DocumentType, 
  EnrollmentBuilder, 
  UqudoIdSDK,
  ReadingConfigurationBuilder
} from 'uqudosdk-react-native';

...
//On App startup
constructor(){
    super()
    new UqudoIdSDK().init();
  }
...

```

Use the below method for setting the locale of the application:

```javascript
...
new UqudoIdSDK().setLocale(<your locale eg. en, ar etc.>);
...
```

To check if a document supports enrollment, reading and facial recognition you can use the below methods:

```javascript
...
const isEnrollmentSupported = await this.sdk.isEnrollmentSupported(DocumentType.UAE_ID);
const isReadingSupported = await this.sdk.isReadingSupported(DocumentType.UAE_ID);
const isFacialRecognitionSupported = await this.sdk.isFacialRecognitionSupported(DocumentType.UAE_ID);
...
```

Below you can find an example on how to initiate the enrollment process for a passport enabling the reading through NFC and facial recognition:

```javascript
var token = "<please put your token here>";
try {
    var passport = new DocumentBuilder()
			      .setDocumentType(DocumentType.PASSPORT)
			      .enableReading(new ReadingConfigurationBuilder()
			          .forceReadingIfSupported(true)
			          .build()
			      )
			      .build();
    var enrollmentConfiguration = new EnrollmentBuilder()
			      .setToken(token)
                              .enableFacialRecognition()
			      .add(passport)
                              .setAppearanceMode(AppearanceMode.SYSTEM)
   			      .build();
   const sdk = new UqudoIdSDK();
   const result = await sdk.enroll(enrollmentConfiguration);
   console.log(result);
} catch (error) {
   console.log(JSON.parse(error.code));
   // {"code":"USER_CANCEL","message":"User canceled the Enrollment process","task":"SCAN"}
}
```

In order to evaluate all the possible options please refer to section [Enrolment Flow](https://docs.uqudo.com/docs/kyc/uqudo-sdk/integration/android/enrolment-flow). The JS interface is the porting of the Kotlin implementation. You can find the JS implementation in uqudoBuilder/uqudo.js under the uqudoid module path.

If **successful**, the response is a JSON Web Signature (JWS). Please refer to section "[SDK result](https://docs.uqudo.com/docs/kyc/uqudo-sdk/sdk-result)" for further details.

In case of a **failure**, the callback returns the following object:

<table><thead><tr><th width="122">Property</th><th width="83">Type</th><th width="99">Optional</th><th width="96">Default</th><th>Description</th></tr></thead><tbody><tr><td>code</td><td>String</td><td>No</td><td>None</td><td>See <a href="../../android/enrolment-flow#handling-the-result">Handling the Result</a></td></tr><tr><td>message</td><td>String</td><td>Yes</td><td>null</td><td>Description of the error if any</td></tr><tr><td>task</td><td>String</td><td>Yes</td><td>null</td><td>See <a href="../../android/enrolment-flow#handling-the-result">Handling the Result</a></td></tr></tbody></table>

Add the following event to enable the tracing mechanism. Please refer to section [Analytics](https://docs.uqudo.com/docs/kyc/uqudo-sdk/integration/android/analytics) for details.

```javascript
(new NativeEventEmitter(NativeModules.UqudoId)).addListener('TraceEvent', (event) => {
     console.log(JSON.stringify(event));
  });
```
