Skip to content

Commit

Permalink
fix authrequest fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu89 committed Jul 9, 2023
1 parent 9bebc7c commit aef8a95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zerologin/elements",
"description": "Zerologin auth web components",
"version": "0.0.11-beta",
"version": "0.0.12-beta",
"private": false,
"files": [
"dist/"
Expand Down
28 changes: 14 additions & 14 deletions src/components/zerologin-sigauth.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ async function getBase64FromImageUrl(url: string): Promise<string> {
async function loadQR(
logoPromise: Promise<string>,
challenge: { challengeId: string; challenge: string }
authRequest: { challengeId: string; challenge: string }
) {
const logo = await logoPromise;
const qr = await new AwesomeQR({
text: challenge.challenge,
text: authRequest.challenge,
size: 280,
logoImage: logo,
whiteMargin: false,
Expand All @@ -128,9 +128,18 @@ async function loadSigauth() {
.replace("https://", "wss://");
const ws = new WebSocket(wsUrl);
ws.onopen = () => {
const authRequest: { challengeId: string; challenge: string } = await ky
.get(`${props.url}/api/v2/sigauth?id=${props.publicId}`)
.json();
sigauth.value = authRequest.challenge;
const logoPromise = getBase64FromImageUrl(logo.value.src);
await loadQR(logoPromise, authRequest);
ws.onopen = async () => {
ws.send(
JSON.stringify({ action: "join", challengeId: challenge.challengeId })
JSON.stringify({ action: "join", challengeId: authRequest.challengeId })
);
};
Expand Down Expand Up @@ -183,7 +192,7 @@ async function loadSigauth() {
ws.send(
JSON.stringify({
action: "offer",
challengeId: challenge.challengeId,
challengeId: authRequest.challengeId,
offer: JSON.stringify(data),
})
);
Expand All @@ -199,15 +208,6 @@ async function loadSigauth() {
peer.signal(icecandidate);
}
};
const challenge: { challengeId: string; challenge: string } = await ky
.get(`${props.url}/api/v2/sigauth?id=${props.publicId}`)
.json();
sigauth.value = challenge.challenge;
const logoPromise = getBase64FromImageUrl(logo.value.src);
await loadQR(logoPromise, challenge);
}
onMounted(async () => {
Expand Down

0 comments on commit aef8a95

Please sign in to comment.