Skip to content

Commit 887c14b

Browse files
committed
* working redirect to mobile
1 parent 5edf344 commit 887c14b

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

vite-web-sdk/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ VITE_TOKEN_SERVER_URL=/api
22
VITE_CLIENT_ID=<your client id>
33
VITE_LOCAL_SERVER_URL=https://your-ip:port/
44
VITE_API_URL=https://demo-api.incodesmile.com
5-
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.69.0.js
5+
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.69.1.js

vite-web-sdk/main.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11

22
// Lets put all the variables needed for all modules in the global scope
3-
const tokenServerURL= import.meta.env.VITE_TOKEN_SERVER_URL
3+
const tokenServerURL= import.meta.env.VITE_TOKEN_SERVER_URL;
4+
const localServerUrl= import.meta.env.VITE_LOCAL_SERVER_URL;
45
let incode;
56
let session;
67
const container = document.getElementById("camera-container");
78

89
async function startOnboardingSession() {
9-
const response = await fetch(`${tokenServerURL}/start`);
10-
const session = await response.json();
11-
return session;
10+
const urlParams = new URLSearchParams(window.location.search);
11+
const uuid = urlParams.get('uuid');
12+
13+
let sessionStartUrl = `${tokenServerURL}/start`
14+
if (uuid) sessionStartUrl +=`?uuid=${uuid}`;
15+
16+
const response = await fetch(sessionStartUrl);
17+
if (!response.ok){
18+
const sessionData = await response.json();
19+
throw new Error(sessionData.error);
20+
}
21+
22+
return await response.json();
1223
}
1324

1425
function showError(e=null) {
1526
container.innerHTML = "<h1>There was an error</h1>";
16-
console.log(e)
27+
console.log(e.message)
28+
}
29+
30+
function renderRedirectToMobile(){
31+
if (incode.isDesktop()) {
32+
incode.renderRedirectToMobile(container, {
33+
onSuccess: () => {
34+
finish();
35+
},
36+
session: session,
37+
url: `${localServerUrl}?uuid=${session.uuid}`
38+
});
39+
} else {
40+
renderFrontIDCamera();
41+
}
1742
}
1843

1944
function renderFrontIDCamera() {
@@ -90,11 +115,15 @@ async function app() {
90115

91116
// Create the single session
92117
container.innerHTML = "<h1>Creating session...</h1>";
93-
session = await startOnboardingSession();
94-
118+
try {
119+
session = await startOnboardingSession();
120+
} catch(e) {
121+
showError(e);
122+
return;
123+
}
95124
// Empty the container and starting the flow
96125
container.innerHTML = "";
97-
renderFrontIDCamera();
126+
renderRedirectToMobile();
98127
} catch (e) {
99128
console.dir(e);
100129
container.innerHTML = "<h1>Something Went Wrong</h1>";

0 commit comments

Comments
 (0)