diff --git a/src/components/PageLayout/Authentication/Authentication.tsx b/src/components/PageLayout/Authentication/Authentication.tsx index 97e72320..efe7b608 100644 --- a/src/components/PageLayout/Authentication/Authentication.tsx +++ b/src/components/PageLayout/Authentication/Authentication.tsx @@ -1,4 +1,5 @@ import Link from 'next/link' +import {useRouter} from 'next/router' import {FC, useState} from 'react' import {AuthContainer} from '@/utils/AuthContainer' @@ -18,6 +19,15 @@ export const Authentication: FC = () => { const {seminar} = useSeminarInfo() + const router = useRouter() + + const redirectLogout = () => { + logout() + if (router.asPath.endsWith('profil') || router.asPath.endsWith('profil/uprava')) { + router.push('/') + } + } + if (!isAuthed) { return ( <> @@ -38,7 +48,7 @@ export const Authentication: FC = () => { return (
Profil - logout()}>Odhlásiť + Odhlásiť
) } diff --git a/src/components/PageLayout/LoginForm/LoginForm.tsx b/src/components/PageLayout/LoginForm/LoginForm.tsx index 12e67c3e..c3af1884 100644 --- a/src/components/PageLayout/LoginForm/LoginForm.tsx +++ b/src/components/PageLayout/LoginForm/LoginForm.tsx @@ -1,3 +1,4 @@ +import {useRouter} from 'next/router' import {FC} from 'react' import {SubmitHandler, useForm} from 'react-hook-form' @@ -24,8 +25,17 @@ export const LoginForm: FC = ({closeOverlay}) => { const {login} = AuthContainer.useContainer() const {handleSubmit, control} = useForm({defaultValues}) + const router = useRouter() + + const redirectClose = () => { + closeOverlay() + if (router.asPath.endsWith('registracia')) { + router.push('/') + } + } + const onSubmit: SubmitHandler = (data) => { - login({data, onSuccess: closeOverlay}) + login({data, onSuccess: redirectClose}) } const requiredRule = {required: '* Toto pole nemôže byť prázdne.'}