From aef8a956a6d2788980f586d01517ac3e9fb6ee63 Mon Sep 17 00:00:00 2001 From: Dolu Date: Sun, 9 Jul 2023 14:50:15 +0200 Subject: [PATCH] fix authrequest fetch --- package.json | 2 +- src/components/zerologin-sigauth.ce.vue | 28 ++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index c192a39..d71c3f1 100644 --- a/package.json +++ b/package.json @@ -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/" diff --git a/src/components/zerologin-sigauth.ce.vue b/src/components/zerologin-sigauth.ce.vue index 4f50b6a..3fcb052 100644 --- a/src/components/zerologin-sigauth.ce.vue +++ b/src/components/zerologin-sigauth.ce.vue @@ -106,11 +106,11 @@ async function getBase64FromImageUrl(url: string): Promise { async function loadQR( logoPromise: Promise, - 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, @@ -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 }) ); }; @@ -183,7 +192,7 @@ async function loadSigauth() { ws.send( JSON.stringify({ action: "offer", - challengeId: challenge.challengeId, + challengeId: authRequest.challengeId, offer: JSON.stringify(data), }) ); @@ -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 () => {