Commit d56280a9 authored by Ermolaev Timur's avatar Ermolaev Timur

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

parent b0374cba
import {Routes, Route, Outlet, Navigate, BrowserRouter} from "react-router-dom"; import {Routes, Route, Outlet, Navigate, BrowserRouter} from "react-router-dom";
import {Container} from "@mui/material"; import {Container} from "@mui/material";
import {useSelector} from "react-redux"; 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 ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
const user = useSelector(state => state.users?.user); const user = useSelector(state => state.users?.user);
console.log(user)
if (!isAllowed && !roles?.includes(user?.role)) { if (!isAllowed && !roles?.includes(user?.role)) {
return <Navigate to={redirectUrl} /> return <Navigate to={redirectUrl} />
} }
...@@ -14,7 +16,6 @@ const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => { ...@@ -14,7 +16,6 @@ const ProtectedRoute = ({isAllowed, roles, redirectUrl, children}) => {
const App = () => { const App = () => {
const user = useSelector(state => state.users?.user); const user = useSelector(state => state.users?.user);
console.log(user)
return ( return (
<BrowserRouter> <BrowserRouter>
<Routes> <Routes>
......
...@@ -30,7 +30,6 @@ const Login = () => { ...@@ -30,7 +30,6 @@ const Login = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { loginError, loading } = useSelector(state => state.users); const { loginError, loading } = useSelector(state => state.users);
console.log(loginError)
const navigate = useNavigate("/") const navigate = useNavigate("/")
const inputChangeHandler = (e) => { const inputChangeHandler = (e) => {
......
...@@ -20,7 +20,6 @@ export const registerUser = (userData, navigate) => { ...@@ -20,7 +20,6 @@ export const registerUser = (userData, navigate) => {
try { try {
const response = await axios.post("/users", userData); const response = await axios.post("/users", userData);
dispatch(registerUserSuccess()) dispatch(registerUserSuccess())
console.log(response)
navigate("/") navigate("/")
} catch (error) { } catch (error) {
if (error.response?.data) { if (error.response?.data) {
...@@ -54,7 +53,6 @@ export const loginUser = (userData, navigate) => { ...@@ -54,7 +53,6 @@ export const loginUser = (userData, navigate) => {
dispatch(loginUserSuccess(response.data)); dispatch(loginUserSuccess(response.data));
navigate("/") navigate("/")
} catch (e) { } catch (e) {
console.dir(e)
dispatch(loginUserFailure(e?.response?.data?.err)) dispatch(loginUserFailure(e?.response?.data?.err))
} }
} }
......
...@@ -5,7 +5,7 @@ const initialState = { ...@@ -5,7 +5,7 @@ const initialState = {
name: 'Ivan', name: 'Ivan',
surname: 'Petrov', surname: 'Petrov',
email: 'test@gmail.com', email: 'test@gmail.com',
role: 'superuser' role: 'user'
}, },
registerError: null, registerError: null,
loginError: 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