Skip to content

Commit

Permalink
added redirections after logging in or out (#253)
Browse files Browse the repository at this point in the history
* added redirections after logging in or out

* added redirections after logging in or out
  • Loading branch information
Smilinko authored Dec 9, 2023
1 parent e1731f1 commit 72a0ba6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/components/PageLayout/Authentication/Authentication.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link from 'next/link'
import {useRouter} from 'next/router'
import {FC, useState} from 'react'

import {AuthContainer} from '@/utils/AuthContainer'
Expand All @@ -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 (
<>
Expand All @@ -38,7 +48,7 @@ export const Authentication: FC = () => {
return (
<div className={styles.authenticationDisplayButtons}>
<Link href={`/${seminar}/profil`}>Profil</Link>
<span onClick={() => logout()}>Odhlásiť</span>
<span onClick={redirectLogout}>Odhlásiť</span>
</div>
)
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/PageLayout/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRouter} from 'next/router'
import {FC} from 'react'
import {SubmitHandler, useForm} from 'react-hook-form'

Expand All @@ -24,8 +25,17 @@ export const LoginForm: FC<ILoginForm> = ({closeOverlay}) => {
const {login} = AuthContainer.useContainer()
const {handleSubmit, control} = useForm<LoginFormValues>({defaultValues})

const router = useRouter()

const redirectClose = () => {
closeOverlay()
if (router.asPath.endsWith('registracia')) {
router.push('/')
}
}

const onSubmit: SubmitHandler<LoginFormValues> = (data) => {
login({data, onSuccess: closeOverlay})
login({data, onSuccess: redirectClose})
}

const requiredRule = {required: '* Toto pole nemôže byť prázdne.'}
Expand Down

0 comments on commit 72a0ba6

Please sign in to comment.