From 6c2e0dbe9ec200f4d23ecb3303c57984d979dd00 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 26 Nov 2022 16:00:18 +0200 Subject: [PATCH] 2fa frontend functionality WIP --- src/pages/Home.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/pages/Home.js b/src/pages/Home.js index 9b81d2c..ec87bf9 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -10,11 +10,10 @@ const Profile = () => { const [twoFactorError, set2FAError] = useState(null); const [qr, setQr] = useState(null); - const enable2FA = async () => { + const displayQr = async () => { const response = await get('/api/user/2fa'); if (response.status !== 200) return set2FAError(response.message); - setQr(response.data); - console.log(qr); + setQr(response.message); }; const authCodeRef = useRef(); @@ -24,10 +23,31 @@ const Profile = () => { if(response.status !== 200) return set2FAError(response.message); }; + const codeRef = useRef(); + const submitCode = async () => { + + const code = codeRef.current.value; + if (!code) return; + const response = await post('/api/user/2fa/verify', { code }); + if (response.status !== 200) return set2FAError(response.message); + + }; + return
+
+

Profile

+ +

Profile Picture

+ +
+ + +
+
+

Settings

@@ -49,17 +69,24 @@ const Profile = () => {

Two Factor

+ {twoFactorError &&

{twoFactorError}

} {!user.twoFactor ?
- + {qr ? +
+ +
+ + +
+
: + }
:
} - {qr && } -
; };