From 3adf346b66b0539c12f8b28f2625bebe9eee12b4 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 24 Nov 2022 13:18:02 +0200 Subject: [PATCH] registration link + copy to clipboard --- src/pages/Login.js | 1 - src/pages/Users.js | 24 ++++++++++++++++++++---- src/util/Util.js | 10 +++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/pages/Login.js b/src/pages/Login.js index cb839ff..2d246f6 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -79,7 +79,6 @@ const TwoFactor = () => { if (!code) return; const result = await post('/api/login/verify', { code }); - console.log(result); if (result.status === 200) { setUser(await fetchUser()); return navigate('/home', { replace: true }); diff --git a/src/pages/Users.js b/src/pages/Users.js index f0dfe93..308bec0 100644 --- a/src/pages/Users.js +++ b/src/pages/Users.js @@ -164,14 +164,30 @@ const CreateUserField = () => { const [link, setLink] = useState(null); const getSignupCode = async () => { - const response = await get('/api/signup/code'); - if(response.status === 200) setLink(response.data); + const response = await get('/api/register/code'); + if (response.status === 200) { + const link = `${window.location.origin}/register?code=${response.data.code}`; + setLink(link); + } + }; + + const copyToClipboard = (event) => { + const text = event.target.innerText; + navigator.clipboard.writeText(text); }; return
- {link ? link : } + {link ? + {link} : + } - {/* TODO: Create form */} +
+ + + + + +
; }; diff --git a/src/util/Util.js b/src/util/Util.js index 1859373..4c2ddb9 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -37,13 +37,13 @@ const parseResponse = async (response) => { }, {}); const success = status >= 200 && status < 300; const base = { success, status }; + + if (status === 401) { + clearSession(); + } + if (headers['content-type']?.includes('application/json')) { const data = await response.json(); - if (status === 401) { - // const currentPath = window.location.pathname; - // if (data.twoFactor && !currentPath.includes('/login/verify')) window.location.pathname = '/login/verify'; - // else if(!data.twoFactor && !currentPath.includes('/login')) window.location.pathname = '/login'; - } return {...base, data}; } return { ...base, message: await response.text() };