-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.js
More file actions
34 lines (26 loc) · 1.01 KB
/
session.js
File metadata and controls
34 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const tokenServerURL= import.meta.env.VITE_TOKEN_SERVER_URL;
const startOnboardingSession = async function() {
const urlParams = new URLSearchParams(window.location.search);
const uniqueId = urlParams.get('uniqueId');
let sessionStartUrl = `${tokenServerURL}/start`
if (uniqueId) sessionStartUrl +=`?uniqueId=${uniqueId}`;
const response = await fetch(sessionStartUrl);
if (!response.ok) {
const sessionData = await response.json();
throw new Error(sessionData.error);
}
return await response.json();
}
const finishOnboardingSession = async function(token) {
// Connect with your backend service to finish the session
const response = await fetch(`${tokenServerURL}/finish`, {
method: "POST",
body: JSON.stringify({token})
});
if (!response.ok) {
const data = await response.json();
throw new Error(data.error);
}
return await response.json();
}
export {startOnboardingSession, finishOnboardingSession};