Commit d56280a9 authored by Ermolaev Timur's avatar Ermolaev Timur

#10 Утвердился, что все работает

parent b0374cba
import {Routes, Route, Outlet, Navigate, BrowserRouter} from "react-router-dom";
import {Container} from "@mui/material";
import {useSelector} from "react-redux";
import AppToolbar from "./components/UI/AppToolBar/AppToolBar";
import AppToolbar from './components/UI/AppToolBar/AppToolbar'
import MyTasks from './containers/MyTasks/MyTasks'
import Login from './containers/Login/Login'
import Register from './containers/Register/Register'
const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
const user = useSelector(state => state.users?.user);
console.log(user)
if (!isAllowed && !roles?.includes(user?.role)) {
return <Navigate to={redirectUrl} />
}
......@@ -14,7 +16,6 @@ const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
const App = () => {
const user = useSelector(state => state.users?.user);
console.log(user)
return (
<BrowserRouter>
<Routes>
......
......@@ -30,7 +30,6 @@ const Login = () => {
const dispatch = useDispatch();
const { loginError, loading } = useSelector(state => state.users);
console.log(loginError)
const navigate = useNavigate("/")
const inputChangeHandler = (e) => {
......
......@@ -20,7 +20,6 @@ export const registerUser = (userData, navigate) => {
try {
const response = await axios.post("/users", userData);
dispatch(registerUserSuccess())
console.log(response)
navigate("/")
} catch (error) {
if (error.response?.data) {
......@@ -54,7 +53,6 @@ export const loginUser = (userData, navigate) => {
dispatch(loginUserSuccess(response.data));
navigate("/")
} catch (e) {
console.dir(e)
dispatch(loginUserFailure(e?.response?.data?.err))
}
}
......
......@@ -5,7 +5,7 @@ const initialState = {
name: 'Ivan',
surname: 'Petrov',
email: 'test@gmail.com',
role: 'superuser'
role: 'user'
},
registerError: null,
loginError: null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment