Compare commits
2 Commits
d7d7d84150
...
004f745bc0
Author | SHA1 | Date | |
---|---|---|---|
004f745bc0 | |||
9fb29bba44 |
@ -9,7 +9,7 @@ import UserControls from './components/UserControls';
|
|||||||
import { useLoginContext } from './structures/UserContext';
|
import { useLoginContext } from './structures/UserContext';
|
||||||
import Login from './pages/Login';
|
import Login from './pages/Login';
|
||||||
import { get, setSession, setSettings } from './util/Util';
|
import { get, setSession, setSettings } from './util/Util';
|
||||||
import PrivateRoute from './structures/PrivateRoute';
|
import { PrivateRoute } from './structures/PrivateRoute';
|
||||||
import { UnauthedRoute } from './structures/UnauthedRoute';
|
import { UnauthedRoute } from './structures/UnauthedRoute';
|
||||||
import Users from './pages/Users';
|
import Users from './pages/Users';
|
||||||
import Admin from './pages/Admin';
|
import Admin from './pages/Admin';
|
||||||
|
@ -2,11 +2,9 @@ import React from 'react';
|
|||||||
import { Navigate, useLocation } from "react-router-dom";
|
import { Navigate, useLocation } from "react-router-dom";
|
||||||
import { getUser } from "../util/Util";
|
import { getUser } from "../util/Util";
|
||||||
|
|
||||||
const PrivateRoute = ({ children }) => {
|
export const PrivateRoute = ({ children }) => {
|
||||||
const user = getUser();
|
const user = getUser();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
if (!user) return <Navigate to='/login' replace state={{ from: location }} />;
|
if (!user) return <Navigate to='/login' replace state={{ from: location }} />;
|
||||||
return children;
|
return children;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PrivateRoute;
|
|
@ -46,7 +46,7 @@ const parseResponse = async (response) => {
|
|||||||
|
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
clearSession();
|
clearSession();
|
||||||
if(!location.pathname.includes('/login')) location.pathname = '/login';
|
if(!location.pathname.includes('/login') && !location.pathname.includes('/register')) location.pathname = '/login';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers['content-type']?.includes('application/json')) {
|
if (headers['content-type']?.includes('application/json')) {
|
||||||
|
Loading…
Reference in New Issue
Block a user