Skip to content

Commit 9d7a74e

Browse files
committed
* started facelogin sample
1 parent f19c623 commit 9d7a74e

File tree

7 files changed

+1156
-0
lines changed

7 files changed

+1156
-0
lines changed

face-login/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VITE_TOKEN_SERVER_URL=<valid server with ssl correctly configured>
2+
VITE_CLIENT_ID=<your client id>
3+
VITE_REDIRECT_URL=https://localhost:5173/
4+
VITE_API_URL=https://demo-api.incodesmile.com
5+
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.61.1.js

face-login/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Vite Web SDK example
2+
This examples runs the basic create session -> frontId -> backID -> processId -> Selfie -> faceMatch -> getFinishStatus flow, the code is simple enough to insert or remove any step
3+
for testing or creating proof of concepts.
4+
5+
# Requirements
6+
Vite requires Node.js version 14.18+, 16+. some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
7+
8+
# Install
9+
Run `npm install`
10+
# Config
11+
Copy `.env.example` to `.env.local` and add your local values
12+
```
13+
VITE_API_URL=https://demo-api.incodesmile.com
14+
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.60.0.js
15+
VITE_CLIENT_ID=
16+
VITE_FLOW_ID=
17+
```
18+
Remember the Flow holds the backend counter part of the process, some configurations there might affect the behavior of the WebSDK here.
19+
20+
# Run
21+
Vite is configured to serve the project using https and and expose him self, so you can easily test with your mobile phone on the local network.
22+
23+
run `npm run dev`
24+
25+
A new server will be exposed, the data will be in the terminal
26+
27+
# Build
28+
run `npm run build`
29+
30+
A new build will be created in `/dist` you can serve that build everywhere just remember to serve with https.
31+
32+
# Testing especific versions locally
33+
You can save the specific version needed under `/public` and change the `VITE_SDK_URL` variable on `.env.local` to something like:
34+
35+
```
36+
VITE_SDK_URL=/name-of-the-js-file.js
37+
```
38+

face-login/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<script src="%VITE_SDK_URL%"></script>
7+
<script type="module" src="/main.js"></script>
8+
<link href="/style.css" rel="stylesheet" />
9+
<title>Vite WebSDK Example</title>
10+
</head>
11+
<body>
12+
<main id="app">
13+
<div id="camera-container"></div>
14+
<div id="finish-container"></div>
15+
</main>
16+
</body>
17+
</html>

face-login/main.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
let onBoarding;
3+
let response;
4+
const container = document.getElementById("camera-container");
5+
6+
function showError(e=null) {
7+
container.innerHTML = "<h1>There was an error</h1>";
8+
console.log(e)
9+
}
10+
11+
function identifyUser(){
12+
onBoarding.renderLogin(container,{
13+
onSuccess: response => {
14+
console.log(response);
15+
finish(response)
16+
// User has an Incode Identity. Add success your logic here
17+
},
18+
onError: error => {
19+
showError(error)
20+
// User not found. Add rejection your logic here
21+
},
22+
});
23+
}
24+
25+
function finish(response) {
26+
const container = document.getElementById("finish-container");
27+
container.innerHTML = "<pre>"+JSON.stringify(response, undefined, 2);+"</pre>";
28+
}
29+
30+
async function app() {
31+
try {
32+
// Create the instance of incode linked to a client
33+
const apiURL = import.meta.env.VITE_API_URL;
34+
const clientId = import.meta.env.VITE_CLIENT_ID;
35+
const apiKey =import.meta.env.VITE_API_KEY;
36+
37+
onBoarding = window.OnBoarding.create({clientId,apiURL,apiKey});
38+
39+
// Incode web_sdk need to preload some core component before being usable
40+
container.innerHTML = "<h1>Warming up...</h1>";
41+
await onBoarding.warmup();
42+
43+
// Empty the container and starting the flow
44+
container.innerHTML = "";
45+
identifyUser();
46+
} catch (e) {
47+
console.dir(e);
48+
container.innerHTML = "<h1>Something Went Wrong</h1>";
49+
throw e;
50+
}
51+
}
52+
53+
document.addEventListener("DOMContentLoaded", app);

face-login/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "vite-vanilla-web-sdk",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite --host",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"devDependencies": {
12+
"vite": "^4.4.11",
13+
"vite-plugin-mkcert": "^1.16.0"
14+
},
15+
"dependencies": {
16+
"dotenv": "^16.3.1"
17+
}
18+
}

0 commit comments

Comments
 (0)