perms + re-auth after passwd change
This commit is contained in:
parent
d775b65738
commit
17b338fc49
@ -48,7 +48,7 @@ function App()
|
|||||||
{
|
{
|
||||||
to: '/home', label: 'Home', items: [
|
to: '/home', label: 'Home', items: [
|
||||||
{ to: '/profile', label: 'Profile', relative: true },
|
{ to: '/profile', label: 'Profile', relative: true },
|
||||||
{ to: '/applications', label: 'Applications', relative: true }
|
{ to: '/applications', label: 'Applications', relative: true, permission: [ 'applications', 5 ] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ import '../css/pages/Home.css';
|
|||||||
import ErrorBoundary from '../util/ErrorBoundary';
|
import ErrorBoundary from '../util/ErrorBoundary';
|
||||||
import Applications from './home/Applications';
|
import Applications from './home/Applications';
|
||||||
import Profile from './home/Profile';
|
import Profile from './home/Profile';
|
||||||
|
import { PermissionBarrier } from '../structures/PermissionBarrier';
|
||||||
|
|
||||||
const Main = () =>
|
const Main = () =>
|
||||||
{
|
{
|
||||||
@ -20,7 +21,11 @@ const Home = () =>
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Main />} />
|
<Route path="/" element={<Main />} />
|
||||||
<Route path="/profile" element={<Profile />} />
|
<Route path="/profile" element={<Profile />} />
|
||||||
<Route path="/applications/*" element={<Applications />} />
|
<Route path="/applications/*" element={
|
||||||
|
<PermissionBarrier permission='applications'>
|
||||||
|
<Applications />
|
||||||
|
</PermissionBarrier>
|
||||||
|
} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</ErrorBoundary>;
|
</ErrorBoundary>;
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { capitalise, get, post } from '../../util/Util';
|
import { capitalise, clearSession, get, post } from '../../util/Util';
|
||||||
import { useLoginContext } from '../../structures/UserContext';
|
import { useLoginContext } from '../../structures/UserContext';
|
||||||
import { FileSelector } from '../../components/InputElements';
|
import { FileSelector } from '../../components/InputElements';
|
||||||
import { ExternalProfile as EP, User } from '../../@types/ApiStructures';
|
import { ExternalProfile as EP, User } from '../../@types/ApiStructures';
|
||||||
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
const TwoFactorControls = ({ user }: {user: User}) =>
|
const TwoFactorControls = ({ user }: {user: User}) =>
|
||||||
{
|
{
|
||||||
@ -94,7 +95,7 @@ const ThirdPartyConnections = ({ user }: {user: User}) =>
|
|||||||
|
|
||||||
const Profile = () =>
|
const Profile = () =>
|
||||||
{
|
{
|
||||||
|
const navigate = useNavigate();
|
||||||
const user = useLoginContext()[0] as User;
|
const user = useLoginContext()[0] as User;
|
||||||
const [ file, setFile ] = useState<File | null>(null);
|
const [ file, setFile ] = useState<File | null>(null);
|
||||||
const [ error, setError ] = useState<string | null>(null);
|
const [ error, setError ] = useState<string | null>(null);
|
||||||
@ -143,6 +144,11 @@ const Profile = () =>
|
|||||||
const data: {username?: string, displayName?: string, password?: string, newPassword?: string} = { username, displayName, password: currentPassword };
|
const data: {username?: string, displayName?: string, password?: string, newPassword?: string} = { username, displayName, password: currentPassword };
|
||||||
if (currentPassword && newPassword && newPasswordRepeat)
|
if (currentPassword && newPassword && newPasswordRepeat)
|
||||||
{
|
{
|
||||||
|
if (currentPassword === newPassword)
|
||||||
|
{
|
||||||
|
button.disabled = false;
|
||||||
|
return setError('Old and new passwords cannot be the same');
|
||||||
|
}
|
||||||
if (newPassword !== newPasswordRepeat)
|
if (newPassword !== newPasswordRepeat)
|
||||||
{
|
{
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
@ -150,9 +156,14 @@ const Profile = () =>
|
|||||||
}
|
}
|
||||||
data.newPassword = newPassword;
|
data.newPassword = newPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await post('/api/user/settings', data);
|
const response = await post('/api/user/settings', data);
|
||||||
console.log(response);
|
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
|
if (response.data?.reAuth)
|
||||||
|
{
|
||||||
|
clearSession();
|
||||||
|
navigate('/login');
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user