|
1 | 1 |
|
2 | 2 | // 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; |
4 | 5 | let incode; |
5 | 6 | let session; |
6 | 7 | const container = document.getElementById("camera-container"); |
7 | 8 |
|
8 | 9 | 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(); |
12 | 23 | } |
13 | 24 |
|
14 | 25 | function showError(e=null) { |
15 | 26 | 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 | + } |
17 | 42 | } |
18 | 43 |
|
19 | 44 | function renderFrontIDCamera() { |
@@ -90,11 +115,15 @@ async function app() { |
90 | 115 |
|
91 | 116 | // Create the single session |
92 | 117 | 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 | + } |
95 | 124 | // Empty the container and starting the flow |
96 | 125 | container.innerHTML = ""; |
97 | | - renderFrontIDCamera(); |
| 126 | + renderRedirectToMobile(); |
98 | 127 | } catch (e) { |
99 | 128 | console.dir(e); |
100 | 129 | container.innerHTML = "<h1>Something Went Wrong</h1>"; |
|
0 commit comments