From 87a872d139bc2c26e6f0c2a6699e657e369709e7 Mon Sep 17 00:00:00 2001 From: Smilinko Date: Fri, 8 Dec 2023 23:09:53 +0100 Subject: [PATCH] added redirections after logging in or out --- .../PageLayout/Authentication/Authentication.tsx | 12 +++++++++++- src/components/PageLayout/LoginForm/LoginForm.tsx | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/components/PageLayout/Authentication/Authentication.tsx b/src/components/PageLayout/Authentication/Authentication.tsx index 97e72320..36f14121 100644 --- a/src/components/PageLayout/Authentication/Authentication.tsx +++ b/src/components/PageLayout/Authentication/Authentication.tsx @@ -7,6 +7,7 @@ import {useSeminarInfo} from '@/utils/useSeminarInfo' import {Overlay} from '../../Overlay/Overlay' import {LoginForm} from '../LoginForm/LoginForm' import styles from './Authentication.module.scss' +import { useRouter } from 'next/router' export const Authentication: FC = () => { const [displayAuthenticationOverlay, setDisplayAuthenticationOverlay] = useState(false) @@ -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..2aaefd54 100644 --- a/src/components/PageLayout/LoginForm/LoginForm.tsx +++ b/src/components/PageLayout/LoginForm/LoginForm.tsx @@ -5,6 +5,7 @@ import {Button} from '@/components/Clickable/Clickable' import styles from '@/components/FormItems/Form.module.scss' import {FormInput} from '@/components/FormItems/FormInput/FormInput' import {AuthContainer} from '@/utils/AuthContainer' +import { useRouter } from 'next/router' type LoginFormValues = { email: string @@ -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.'}