registration link + copy to clipboard
This commit is contained in:
parent
487ad5e736
commit
3adf346b66
@ -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 });
|
||||
|
@ -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 <div className="">
|
||||
{link ? link : <button onClick={getSignupCode} className="is-center">Create sign-up link</button>}
|
||||
{link ?
|
||||
<span onClick={copyToClipboard}>{link}</span> :
|
||||
<button onClick={getSignupCode} className="is-center">Create sign-up link</button>}
|
||||
|
||||
{/* TODO: Create form */}
|
||||
<form>
|
||||
<label htmlFor="username">Username</label>
|
||||
<input autoComplete="off" type='text' id='username' />
|
||||
|
||||
<label htmlFor="password">Password</label>
|
||||
<input autoComplete="off" type='password' id='username' />
|
||||
</form>
|
||||
</div>;
|
||||
|
||||
};
|
||||
|
@ -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() };
|
||||
|
Loading…
Reference in New Issue
Block a user