login-with-facepass 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +56 -25
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { ScanFace } from 'lucide-react';
|
|
3
3
|
|
|
4
|
-
const be_endpoint = ""
|
|
4
|
+
const be_endpoint = "https://facepass-be-ecd6bfesh4f0b5hs.belgiumcentral-01.azurewebsites.net";
|
|
5
5
|
|
|
6
6
|
const createChallenge = async ({ email }) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
7
|
+
const params = new URLSearchParams({ Email: email });
|
|
8
|
+
|
|
9
|
+
const response = await fetch(
|
|
10
|
+
`${be_endpoint}/Public/login?${params.toString()}`,
|
|
11
|
+
{
|
|
12
|
+
method: "GET",
|
|
13
|
+
}
|
|
14
|
+
);
|
|
16
15
|
|
|
17
|
-
const
|
|
16
|
+
const text = await response.text();
|
|
17
|
+
let data
|
|
18
|
+
try {
|
|
19
|
+
data = text? JSON.parse(text) : {};
|
|
20
|
+
} catch (error) {
|
|
21
|
+
data = {"message":text}
|
|
22
|
+
}
|
|
18
23
|
return data;
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
const challengeApproval = async ({challengeId}) => {
|
|
22
|
-
|
|
23
|
-
const response = await fetch(be_endpoint +
|
|
27
|
+
const params = new URLSearchParams({ id: challengeId });
|
|
28
|
+
const response = await fetch(be_endpoint + `/Public/checkChallengeStatus?${params}`, {
|
|
24
29
|
method: "GET",
|
|
25
30
|
headers: {
|
|
26
31
|
"Content-Type": "application/json"
|
|
27
|
-
}
|
|
28
|
-
body: JSON.stringify({
|
|
29
|
-
"challengeId": challengeId
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
+
}
|
|
32
33
|
})
|
|
33
34
|
|
|
34
35
|
const data = await response.json();
|
|
@@ -41,13 +42,44 @@ const LoginWithFacePass = ({ setJwt, setStatus }) => {
|
|
|
41
42
|
const [showPopup, setShowPopup] = useState(false);
|
|
42
43
|
const [email, setEmail] = useState("");
|
|
43
44
|
|
|
44
|
-
const handleSubmit = () => {
|
|
45
|
+
const handleSubmit = async () => {
|
|
45
46
|
setShowPopup(false);
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
const data = await createChallenge({email});
|
|
49
|
+
|
|
50
|
+
console.log("HELLO")
|
|
51
|
+
console.log(data)
|
|
52
|
+
const challengeId = data.challengeId;
|
|
53
|
+
|
|
54
|
+
const MAX_TIME = 300000; // 5 minutes
|
|
55
|
+
|
|
56
|
+
const pollChallenge = async (challengeId, startTime = Date.now()) => {
|
|
57
|
+
const result = await challengeApproval({ challengeId });
|
|
58
|
+
|
|
59
|
+
console.log(result);
|
|
60
|
+
|
|
61
|
+
// stop if approved
|
|
62
|
+
if (result.status === "approved") {
|
|
63
|
+
setJwt(result.jwt);
|
|
64
|
+
setStatus(result.status);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (result.status === "rejected"){
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// stop if timeout reached
|
|
73
|
+
if (Date.now() - startTime > MAX_TIME) {
|
|
74
|
+
console.log("Polling timeout");
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
48
77
|
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
// poll again after 500 ms
|
|
79
|
+
setTimeout(() => pollChallenge(challengeId, startTime), 500);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
pollChallenge(challengeId);
|
|
51
83
|
};
|
|
52
84
|
|
|
53
85
|
const styles = {
|
|
@@ -114,7 +146,7 @@ const LoginWithFacePass = ({ setJwt, setStatus }) => {
|
|
|
114
146
|
};
|
|
115
147
|
|
|
116
148
|
return (
|
|
117
|
-
|
|
149
|
+
<>
|
|
118
150
|
<button
|
|
119
151
|
className="demo-btn standard-btn"
|
|
120
152
|
onClick={() => setShowPopup(true)}
|
|
@@ -158,10 +190,9 @@ const LoginWithFacePass = ({ setJwt, setStatus }) => {
|
|
|
158
190
|
</div>
|
|
159
191
|
</div>
|
|
160
192
|
)}
|
|
161
|
-
|
|
193
|
+
</>
|
|
162
194
|
);
|
|
163
195
|
};
|
|
164
196
|
|
|
165
197
|
|
|
166
|
-
export { LoginWithFacePass };
|
|
167
198
|
export default LoginWithFacePass;
|