misc fixes n shit

This commit is contained in:
Erik 2022-11-23 00:39:43 +02:00
parent c16b3cd047
commit bb26e84f90
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
6 changed files with 26 additions and 21 deletions

View File

@ -226,7 +226,7 @@
"no-useless-return": "error",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "error",
"no-warning-comments": "warn",
"no-whitespace-before-property": "error",
"nonblock-statement-body-position": "error",
"object-curly-newline": "error",

View File

@ -26,7 +26,7 @@
-->
<title>Framework dashboard</title>
</head>
<body>
<body class="is-full-screen">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--

View File

@ -30,7 +30,7 @@ function App() {
];
return (
<div className='app'>
<div className='app is-full-screen'>
<header>
<UserControls />
@ -42,7 +42,6 @@ function App() {
{user ?
<Sidebar>
SIDEBAR
<SidebarMenu menuItems={menuItems} />
</Sidebar>
: null}

View File

@ -4,7 +4,7 @@ import NavLink from '../structures/NavLink';
const Sidebar = ({children}) => {
return <div className='sidebar'>
return <div className='sidebar card'>
{children}
</div>;

View File

@ -18,7 +18,6 @@ const CredentialFields = () => {
const [, setUser] = useLoginContext();
const [fail, setFail] = useState(false);
const navigate = useNavigate();
console.log(fail);
const loginClick = async () => {
const username = document.getElementById('username').value;
@ -27,12 +26,12 @@ const CredentialFields = () => {
const result = await post('/api/login', { username, password });
console.log(result);
if (!result.success) {
if (![200, 302].includes(result.status)) {
setFail(true);
return;
}
if (!result.twoFactor) {
if (!result.data.twoFactor) {
setUser(await fetchUser());
return navigate('/home');
}
@ -45,7 +44,7 @@ const CredentialFields = () => {
<img className="logoImg mb-4" src={logoImg}></img>
</div>
<div className="card mb-3 is-center dir-column">
{fail ? 'Invalid credentials' : ''}
{fail ? <p>Invalid credentials</p> : null}
<h2>Log in</h2>
<input autoComplete='off' placeholder='Username' required id='username' type='text' autoFocus />
@ -72,6 +71,7 @@ const CredentialFields = () => {
const TwoFactor = () => {
const [fail, setFail] = useState(false);
const [, setUser] = useLoginContext();
const navigate = useNavigate();
const twoFactorClick = async () => {
@ -80,14 +80,15 @@ const TwoFactor = () => {
const result = await post('/api/login/verify', { code });
console.log(result);
if (result.success) {
if (result.status === 200) {
setUser(await fetchUser());
return navigate('/home', { replace: true });
}
// else throw error?
setFail(true);
};
return <div className="card mb-3 is-center dir-column">
{fail ? <p>Invalid code</p> : null}
<h2>Verification code</h2>
<input autoComplete='off' placeholder='Code' required id='2faCode' type='password' />
<button onClick={twoFactorClick}>Enter</button>
@ -98,7 +99,7 @@ const Login = () => {
document.body.classList.add('bg-triangles');
return <div className="row is-center is-full-screen is-marginless">
<div className='col-6 col-6-md col-3-lg'>
<div className='dingus col-6 col-6-md col-3-lg'>
<Routes>
<Route path='/' element={<CredentialFields />} />

View File

@ -20,11 +20,10 @@ export const fetchUser = async (force = false) => {
const user = getUser();
if (!force && user) return user;
const result = await fetch('/api/user');
const result = await get('/api/user');
if (result.status === 200) {
const data = await result.json();
setSession(data);
return data;
setSession(result.data);
return result.data;
}
return null;
};
@ -40,6 +39,11 @@ const parseResponse = async (response) => {
const base = { success, status };
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() };
@ -53,6 +57,7 @@ export const post = async (url, body) => {
},
body: JSON.stringify(body)
});
console.log(response);
return parseResponse(response);
};