diff --git a/src/App.tsx b/src/App.tsx index 64dd5ab0..fd780f64 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,7 +3,7 @@ import Layout from './layouts/layout/layout.tsx'; import Home from './pages/home'; import Profile from './pages/profile/index.tsx'; import { ProtectedRoute } from './utils/protected-route.tsx'; -// import { useAuth } from './hooks/use-auth.ts'; +import { useAuth } from './hooks/use-auth.ts'; import Product from '@pages/product/index.tsx'; import Catalog from '@pages/catalog/index.tsx'; import { URLS } from '@data/constants.ts'; @@ -17,7 +17,6 @@ import ProfileFavorites from '@pages/profile/profile-favorites/index.tsx'; // import Checkout from '@pages/checkout/index.tsx'; import ShoppingCart from '@pages/shopping-cart/index.tsx'; - // импорт временных массивов для отображения каталогов и продуктов // временное решение для верстки, потом удалить @@ -28,7 +27,7 @@ import ShoppingCart from '@pages/shopping-cart/index.tsx'; // function App() { - // const { isLoggedIn } = useAuth(); + const { isLoggedIn } = useAuth(); return (
@@ -41,7 +40,7 @@ function App() { } /> } + element={} > } /> Мои заказы} /> diff --git a/src/components/popups/popup-login/index.tsx b/src/components/popups/popup-login/index.tsx index 42772d98..eea4d247 100644 --- a/src/components/popups/popup-login/index.tsx +++ b/src/components/popups/popup-login/index.tsx @@ -7,6 +7,7 @@ import { useFormAndValidation } from '@hooks/use-form-and-validation.ts'; import api from '@services/api.ts'; import Cookies from 'js-cookie'; import { useAuth } from '@hooks/use-auth.ts'; +import { useNavigate } from 'react-router'; const PopupLogin: React.FC = () => { const { values, handleChange, validateInputsHandleSubmit, errors, isValid, resetForm } = @@ -14,6 +15,7 @@ const PopupLogin: React.FC = () => { const { popupState, handleClosePopup, handleOpenPopup } = usePopup(); const { checkAuthentication } = useAuth(); const [disabledButton, setDisabledButton] = useState(false); + const navigate = useNavigate(); function onSubmitLogin(e: React.FormEvent) { e.preventDefault(); @@ -32,12 +34,15 @@ const PopupLogin: React.FC = () => { email: `${values.login_email}`, }) .then((data) => { - handleClosePopup('openPopupLogin'); Cookies.set('token', data.auth_token, { expires: 14, }); - checkAuthentication(); + }) + .then(() => checkAuthentication()) + .then(() => { + handleClosePopup('openPopupLogin'); resetForm(); + navigate('/profile'); }) .catch((err) => { console.log(err); diff --git a/src/components/popups/popup-registration/index.tsx b/src/components/popups/popup-registration/index.tsx index 0fd1b91b..6889d890 100644 --- a/src/components/popups/popup-registration/index.tsx +++ b/src/components/popups/popup-registration/index.tsx @@ -39,6 +39,7 @@ const PopupRegistration: React.FC = () => { .then(() => { handleClosePopup('openPopupRegistration'); resetForm(); + handleOpenPopup('openPopupLogin'); }) .catch((err) => { console.log(err); @@ -132,14 +133,14 @@ const PopupRegistration: React.FC = () => {

- Нет аккаунта?{' '} + Есть аккаунт?{' '}

diff --git a/src/contexts/auth-context.tsx b/src/contexts/auth-context.tsx index a6bc8593..3843e19a 100644 --- a/src/contexts/auth-context.tsx +++ b/src/contexts/auth-context.tsx @@ -6,7 +6,7 @@ type AuthContextType = { user: Record; loading: boolean; updateUsers: (newUserData: Record) => void; - checkAuthentication: () => void; + checkAuthentication: () => Promise; }; const AuthContext = createContext({ @@ -14,7 +14,7 @@ const AuthContext = createContext({ user: {}, loading: true, updateUsers: () => {}, - checkAuthentication: () => {}, + checkAuthentication: () => Promise.resolve(), }); type AuthProviderProps = {