Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added redirections after logging in or out #253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading