misc fixes n shit
This commit is contained in:
parent
c16b3cd047
commit
bb26e84f90
@ -226,7 +226,7 @@
|
|||||||
"no-useless-return": "error",
|
"no-useless-return": "error",
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"no-void": "error",
|
"no-void": "error",
|
||||||
"no-warning-comments": "error",
|
"no-warning-comments": "warn",
|
||||||
"no-whitespace-before-property": "error",
|
"no-whitespace-before-property": "error",
|
||||||
"nonblock-statement-body-position": "error",
|
"nonblock-statement-body-position": "error",
|
||||||
"object-curly-newline": "error",
|
"object-curly-newline": "error",
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
-->
|
-->
|
||||||
<title>Framework dashboard</title>
|
<title>Framework dashboard</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body class="is-full-screen">
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
<!--
|
<!--
|
||||||
|
13
src/App.js
13
src/App.js
@ -30,7 +30,7 @@ function App() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='app'>
|
<div className='app is-full-screen'>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<UserControls />
|
<UserControls />
|
||||||
@ -42,7 +42,6 @@ function App() {
|
|||||||
|
|
||||||
{user ?
|
{user ?
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
SIDEBAR
|
|
||||||
<SidebarMenu menuItems={menuItems} />
|
<SidebarMenu menuItems={menuItems} />
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
: null}
|
: null}
|
||||||
@ -50,11 +49,11 @@ function App() {
|
|||||||
<div className='main-content'>
|
<div className='main-content'>
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path='/home/*' element={<PrivateRoute><Home /></PrivateRoute >} />
|
<Route path='/home/*' element={<PrivateRoute><Home /></PrivateRoute >} />
|
||||||
<Route path='/users/*' element={<PrivateRoute><Users /></PrivateRoute >} />
|
<Route path='/users/*' element={<PrivateRoute><Users /></PrivateRoute >} />
|
||||||
<Route path='/admin/*' element={<PrivateRoute><Admin /></PrivateRoute >} />
|
<Route path='/admin/*' element={<PrivateRoute><Admin /></PrivateRoute >} />
|
||||||
<Route path='/login/*' element={<UnauthedRoute><Login /></UnauthedRoute>} />
|
<Route path='/login/*' element={<UnauthedRoute><Login /></UnauthedRoute>} />
|
||||||
<Route path='*' element={<Navigate to='/home' />} />
|
<Route path='*' element={<Navigate to='/home' />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,7 +4,7 @@ import NavLink from '../structures/NavLink';
|
|||||||
|
|
||||||
const Sidebar = ({children}) => {
|
const Sidebar = ({children}) => {
|
||||||
|
|
||||||
return <div className='sidebar'>
|
return <div className='sidebar card'>
|
||||||
{children}
|
{children}
|
||||||
</div>;
|
</div>;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ const CredentialFields = () => {
|
|||||||
const [, setUser] = useLoginContext();
|
const [, setUser] = useLoginContext();
|
||||||
const [fail, setFail] = useState(false);
|
const [fail, setFail] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
console.log(fail);
|
|
||||||
|
|
||||||
const loginClick = async () => {
|
const loginClick = async () => {
|
||||||
const username = document.getElementById('username').value;
|
const username = document.getElementById('username').value;
|
||||||
@ -27,12 +26,12 @@ const CredentialFields = () => {
|
|||||||
|
|
||||||
const result = await post('/api/login', { username, password });
|
const result = await post('/api/login', { username, password });
|
||||||
console.log(result);
|
console.log(result);
|
||||||
if (!result.success) {
|
if (![200, 302].includes(result.status)) {
|
||||||
setFail(true);
|
setFail(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.twoFactor) {
|
if (!result.data.twoFactor) {
|
||||||
setUser(await fetchUser());
|
setUser(await fetchUser());
|
||||||
return navigate('/home');
|
return navigate('/home');
|
||||||
}
|
}
|
||||||
@ -45,7 +44,7 @@ const CredentialFields = () => {
|
|||||||
<img className="logoImg mb-4" src={logoImg}></img>
|
<img className="logoImg mb-4" src={logoImg}></img>
|
||||||
</div>
|
</div>
|
||||||
<div className="card mb-3 is-center dir-column">
|
<div className="card mb-3 is-center dir-column">
|
||||||
{fail ? 'Invalid credentials' : ''}
|
{fail ? <p>Invalid credentials</p> : null}
|
||||||
<h2>Log in</h2>
|
<h2>Log in</h2>
|
||||||
|
|
||||||
<input autoComplete='off' placeholder='Username' required id='username' type='text' autoFocus />
|
<input autoComplete='off' placeholder='Username' required id='username' type='text' autoFocus />
|
||||||
@ -72,6 +71,7 @@ const CredentialFields = () => {
|
|||||||
|
|
||||||
const TwoFactor = () => {
|
const TwoFactor = () => {
|
||||||
|
|
||||||
|
const [fail, setFail] = useState(false);
|
||||||
const [, setUser] = useLoginContext();
|
const [, setUser] = useLoginContext();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const twoFactorClick = async () => {
|
const twoFactorClick = async () => {
|
||||||
@ -80,14 +80,15 @@ const TwoFactor = () => {
|
|||||||
|
|
||||||
const result = await post('/api/login/verify', { code });
|
const result = await post('/api/login/verify', { code });
|
||||||
console.log(result);
|
console.log(result);
|
||||||
if (result.success) {
|
if (result.status === 200) {
|
||||||
setUser(await fetchUser());
|
setUser(await fetchUser());
|
||||||
return navigate('/home', { replace: true });
|
return navigate('/home', { replace: true });
|
||||||
}
|
}
|
||||||
// else throw error?
|
setFail(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
return <div className="card mb-3 is-center dir-column">
|
return <div className="card mb-3 is-center dir-column">
|
||||||
|
{fail ? <p>Invalid code</p> : null}
|
||||||
<h2>Verification code</h2>
|
<h2>Verification code</h2>
|
||||||
<input autoComplete='off' placeholder='Code' required id='2faCode' type='password' />
|
<input autoComplete='off' placeholder='Code' required id='2faCode' type='password' />
|
||||||
<button onClick={twoFactorClick}>Enter</button>
|
<button onClick={twoFactorClick}>Enter</button>
|
||||||
@ -98,7 +99,7 @@ const Login = () => {
|
|||||||
document.body.classList.add('bg-triangles');
|
document.body.classList.add('bg-triangles');
|
||||||
|
|
||||||
return <div className="row is-center is-full-screen is-marginless">
|
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>
|
<Routes>
|
||||||
<Route path='/' element={<CredentialFields />} />
|
<Route path='/' element={<CredentialFields />} />
|
||||||
|
@ -20,11 +20,10 @@ export const fetchUser = async (force = false) => {
|
|||||||
const user = getUser();
|
const user = getUser();
|
||||||
if (!force && user) return user;
|
if (!force && user) return user;
|
||||||
|
|
||||||
const result = await fetch('/api/user');
|
const result = await get('/api/user');
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
const data = await result.json();
|
setSession(result.data);
|
||||||
setSession(data);
|
return result.data;
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@ -40,6 +39,11 @@ const parseResponse = async (response) => {
|
|||||||
const base = { success, status };
|
const base = { success, status };
|
||||||
if (headers['content-type']?.includes('application/json')) {
|
if (headers['content-type']?.includes('application/json')) {
|
||||||
const data = await response.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, data};
|
||||||
}
|
}
|
||||||
return { ...base, message: await response.text() };
|
return { ...base, message: await response.text() };
|
||||||
@ -53,6 +57,7 @@ export const post = async (url, body) => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
console.log(response);
|
||||||
return parseResponse(response);
|
return parseResponse(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user