symisc / faceio-npm Goto Github PK
View Code? Open in Web Editor NEWNPM Package for FACEIO's fio.js
Home Page: https://faceio.net/integration-guide
License: Apache License 2.0
NPM Package for FACEIO's fio.js
Home Page: https://faceio.net/integration-guide
License: Apache License 2.0
I'm trying to handle errors, the same way it's stated in the documentation, but when I log the error, all I get is a number:
Here is my code
async authenticateUser() {
await faceio.authenticate({
'locale': 'es' // Default user locale
}).then((userData: any) => {
console.log(userData)
console.log('Success, user identified')
console.log('Linked facial Id: ' + userData.facialId)
console.log('Payload: ' + JSON.stringify(userData.payload))
}).catch((errCode: any) => {
console.error(errCode)
this.handleError(errCode)
// handle authentication failure. Visit:
// https://faceio.net/integration-guide#error-codes
// for the list of all possible error codes
}).finally(() => {
faceio.restartSession()
})
},
According to your last answer error codes are integers, and we should create a function to handle errors... you gave me a link to the documentation (which I have to say, it's very poor), in your documentation, there is NOTHING mentioning that errors are integers.
Here is my code
async authenticateUser() {
await faceio.authenticate({
'locale': 'es' // Default user locale
}).then((userData: any) => {
console.log(userData)
console.log('Success, user identified')
console.log('Linked facial Id: ' + userData.facialId)
console.log('Payload: ' + JSON.stringify(userData.payload))
}).catch((errCode: any) => {
console.error(errCode)
this.handleError(errCode)
// handle authentication failure. Visit:
// https://faceio.net/integration-guide#error-codes
// for the list of all possible error codes
}).finally(() => {
faceio.restartSession()
})
},
I have my own handle error function like this:
export const handleError = (errCode: any) => {
console.log('handleError: ', errCode)
const errorMessages: { [key: number]: string } = {
1: 'Access to the Camera stream was denied by the end user', // 'fioErrCode.PERMISSION_REFUSED'
2: 'No faces were detected during the enroll or authentication process', // 'fioErrCode.NO_FACES_DETECTED'
3: "Unrecognized face on this application's Facial Index", // 'fioErrCode.UNRECOGNIZED_FACE'
4: 'Two or more faces were detected during the scan process', // 'fioErrCode.MANY_FACES'
5: 'User enrolled previously (facial features already recorded). Cannot enroll again!', // 'fioErrCode.FACE_DUPLICATION'
6: 'Presentation (Spoof) Attack (PAD) detected during the scan process', // 'fioErrCode.PAD_ATTACK'
7: 'Calculated Facial Vectors of the user being enrolled do not match', // 'fioErrCode.FACE_MISMATCH'
8: 'Wrong PIN code supplied by the user being authenticated', // 'fioErrCode.WRONG_PIN_CODE'
9: 'Server side error', // 'fioErrCode.PROCESSING_ERR'
10: 'Your application is not allowed to perform the requested operation (eg. Invalid ID, Blocked, Paused, etc.). Refer to the FACEIO Console for additional information', // 'fioErrCode.UNAUTHORIZED'
11: 'Terms & Conditions set out by FACEIO/host application rejected by the end user', // 'fioErrCode.TERMS_NOT_ACCEPTED'
12: 'The FACEIO Widget could not be (or is being) injected onto the client DOM', // 'fioErrCode.UI_NOT_READY'
13: 'Client session expired. The first promise was already fulfilled but the host application failed to act accordingly', // 'fioErrCode.SESSION_EXPIRED'
14: 'Ongoing operation timed out (eg, Camera access permission, ToS accept delay, Face not yet detected, Server Reply, etc.)', // 'fioErrCode.TIMEOUT'
15: 'Widget instantiation requests exceeded for freemium applications. Does not apply for upgraded applications', // 'fioErrCode.TOO_MANY_REQUESTS'
16: 'Origin or Referer HTTP request header is empty or missing', // 'fioErrCode.EMPTY_ORIGIN'
17: 'Domain origin is forbidden from instantiating fio.js', // 'fioErrCode.FORBIDDDEN_ORIGIN'
18: 'Country ISO-3166-1 Code is forbidden from instantiating fio.js', // 'fioErrCode.FORBIDDDEN_COUNTRY'
19: 'Another authentication or enrollment session is in progress', // 'fioErrCode.SESSION_IN_PROGRESS'
20: 'Error while establishing network connection with the target FACEIO processing node', // 'fioErrCode.NETWORK_IO'
};
alert(errorMessages[errCode] || 'Unknown error occurred');
};
As you can see I had to assume that the integer errorCodes are ordered the way it's listed in your documentation, since there is NOTHING indicating how this should be handled, for example in your documentation you state this in the boilerplate example:
switch (errCode) {
case fioErrCode.PERMISSION_REFUSED:
console.log("Access to the Camera stream was denied by the end user");
break;
case fioErrCode.NO_FACES_DETECTED:
console.log("No faces were detected during the enroll or authentication process");
break;
//... the rest of the code
but fioErrCode
is never defined in your boilerplate... also if it's true that the integers are ordered the way they are listed in your documentation (which I have to assume), I'm getting error codes like 21, which points to nothing!....
Please explain this... be consise, fix your documentation, and provide a reproducible link to see how should this work if possible!.
So, this wasn't happening before the last update... now when I enroll a person, the payload
, its not beign saved...
This is my code:
console.log([
data.uid,
data.email,
data.first_name,
data.company,
data.department
])
//This console.log returns correctly strings... so everything should work!
faceio.enroll({
enrollIntroTimeout: 5,
userConsent: true,
locale: 'es', // Default user locale
payload: {
/* The payload we want to associate with this particular user which is forwarded back to us upon future authentication of this user.*/
'uid': data.uid,
'email': data.email,
'first_name': data.first_name,
'company': data.company,
'department': data.department,
}
})
Enrollment succeeds, but when authenticating, the payload returned is null
.
Please help!
It would be nice to have a selector with available cameras on device to select, or a button to switch between them... for example on a mobile phone you could let the camera switch between front or back camera.
Thanks in advance!.
So, since you decided to delete my last Issue, I'm going to recapitulate again about this error...
According to your documentation, when calling for the fioErrCodes which you did introduce in the last update... all we had to do was this:
const fioErrCode = faceio.fetchAllErrorCodes();
After my Issue over which you said that was my mistake, (even when I DID follow your documentation), you suggested to change the const name to fioErrs
.
As a proof of that, you changed your README
file yesterday, with this change:
const fioErrs = faceio.fetchAllErrorCodes();
So I did as you suggested, and this didn't work either, you claimed that somewhere I redeclared fioErrCode
somewhere in my code... after digging for what whas happening I found out that your library can not be instanciated multiple times.
Instantiating your library multiple times leads to errors like this... this SHOULD be stated in your documentation... because it's more than normal that a complex web application will have multiple parts and possibly the need to instanciate a library multiple times, or instead you should not declare anything in the global scope of your library, which will lead to errors like the mentioned here.
By declaring a constant like fioErrCode in the global scope, the library assumes that it will be the only one using that specific identifier. However, when multiple instances of the library are instantiated, each instance tries to define the same constant, resulting in the "Identifier 'fioErrCode' has already been declared" error.
Ideally, libraries should define their constants within their own scopes, encapsulating them to prevent conflicts with other code in the project. This can be achieved through proper module bundling and encapsulation techniques.
This could potentially lead to errors with other libraries in the future, so hopefully you will choose to fix this in your library instead of forcing users to instantiate once.
Hopefully this time my issue will not be deleted, and this will be helpful for as feedback for your library.
This security function should be included in the starter plan, without something so basic like this for a face authentication, it makes no sense to even pay the starter plan, which should already include basic functionality like this....
If face recognition is displayed as an authentication system every paid plan should have this included. Please consider this, otherwise it makes no sense to pay $20 more for a basic functionality that compromises the whole idea of authentication with FaceIO.
So, here's another not clear thing...
In the dashboard, specifically in the metrics dashboard, right now I only have 1 enrollment, but it shows multiple unique facial id like if there are more than just one added face... actually if I try to delete each one (using the GET method) it fails, except for the last one, which is the real one, once I delete the last record, all the other ones are deleted also...
Aditionally please be more consise and clear with the documentation!.
Is there any way I can remove the faceio branding? I think paid users should be able to remove branding, specially when clicking on your logo takes away users from the main application to your website.
Currently Widget customization is very poor in options... even when your documentation says it's possible to customize it.
I don't understand why by default we have to wait this long in every part of the enrollment process (it also happens when authenticating)
As far as I understand, according to the documentation, I should be able to set the timeouts in the parameters of the function... but this makes no effect at all.
My enrollment function looks like this:
const enrollNewUser = async () => {
await faceio.enroll({
enrollIntroTimeout: 2,
userConsent: false,
locale: 'auto', // Default user locale
payload: {
/* The payload we want to associate with this particular user which is forwarded back to us upon future authentication of this user.*/
uid: 123456, // Dummy ID linked to this particular user
email: '[email protected]',
dni: '11111111',
phone: '11111111',
gender: 'male',
birthday: '01/01/1000'
}
}).then(userInfo => {
// User Successfully Enrolled!
alert(
`User Successfully Enrolled! Details:
Unique Facial ID: ${userInfo.facialId}
Enrollment Date: ${userInfo.timestamp}
Gender: ${userInfo.details.gender}
Age Approximation: ${userInfo.details.age}`
);
console.log(userInfo);
// handle success, save the facial ID (userInfo.facialId), redirect to the dashboard...
}).catch(errCode => {
// Something went wrong during enrollment, log the failure
handleError(errCode);
})
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.