1# @ohos.userIAM.faceAuth (Facial Authentication) 2 3The **userIAM.faceAuth** module provides APIs for face enrollment. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```js 14import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; 15``` 16 17## FaceAuthManager 18 19Provides APIs for facial authentication management. 20 21### constructor 22 23constructor() 24 25A constructor used to create a **FaceAuthManager** object. 26 27**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth 28 29**Return value** 30 31| Type | Description | 32| ---------------------- | -------------------- | 33| [FaceAuthManager](#faceauthmanager) | **FaceAuthManager** object.| 34 35**Example** 36 37```js 38import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; 39 40let faceAuthManager = new userIAM_faceAuth.FaceAuthManager(); 41``` 42 43### setSurfaceId 44 45setSurfaceId(surfaceId: string): void; 46 47Sets an [XComponent surface ID](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid) for the face preview page in the face enrollment process. This API must be used with [AddCredential](./js-apis-osAccount.md#addcredential8). 48 49**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth 50 51**Required permissions**: ohos.permission.MANAGE_USER_IDM 52 53**Parameters** 54 55| Name | Type | Mandatory| Description | 56| -------------- | ---------------------------------- | ---- | -------------------------- | 57| surfaceId | string | Yes | ID of the surface held by the [XComponent](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid).| 58 59For details about the following error codes, see [User Authentication Error Codes](../errorcodes/errorcode-useriam.md). 60 61**Error codes** 62 63| ID| Error Message| 64| -------- | ------- | 65| 201 | Permission verification failed. | 66| 202 | The caller is not a system application. | 67| 12700001 | The operation is failed. | 68 69**Example** 70 71```js 72import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; 73 74// The surfaceId is obtained from the XComponent control. The surfaceId here is only an example. 75let surfaceId = "123456"; 76let manager = new userIAM_faceAuth.FaceAuthManager(); 77try { 78 manager.setSurfaceId(surfaceId); 79 console.info("Set the surface ID successfully"); 80} catch (e) { 81 console.error("Failed to set the surface ID, error = " + e); 82} 83``` 84