🐛 Login not redirecting
This commit is contained in:
@@ -18,6 +18,7 @@ import { useTranslation } from 'next-i18next';
|
|||||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
import { useState } from 'react';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { getServerAuthSession } from '~/server/auth';
|
import { getServerAuthSession } from '~/server/auth';
|
||||||
import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
||||||
@@ -29,6 +30,8 @@ export default function LoginPage() {
|
|||||||
const { t } = useTranslation(['authentication/login']);
|
const { t } = useTranslation(['authentication/login']);
|
||||||
const queryParams = useRouter().query as { error?: 'CredentialsSignin' | (string & {}) };
|
const queryParams = useRouter().query as { error?: 'CredentialsSignin' | (string & {}) };
|
||||||
const { i18nZodResolver } = useI18nZodResolver();
|
const { i18nZodResolver } = useI18nZodResolver();
|
||||||
|
const router = useRouter();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof signInSchema>>({
|
const form = useForm<z.infer<typeof signInSchema>>({
|
||||||
validateInputOnChange: true,
|
validateInputOnChange: true,
|
||||||
@@ -37,11 +40,18 @@ export default function LoginPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = (values: z.infer<typeof signInSchema>) => {
|
const handleSubmit = (values: z.infer<typeof signInSchema>) => {
|
||||||
|
setIsLoading(true);
|
||||||
signIn('credentials', {
|
signIn('credentials', {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
name: values.name,
|
name: values.name,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
callbackUrl: '/',
|
callbackUrl: '/',
|
||||||
|
}).then((response) => {
|
||||||
|
if (!response?.ok) {
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
router.push('/manage');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,7 +85,7 @@ export default function LoginPage() {
|
|||||||
{...form.getInputProps('password')}
|
{...form.getInputProps('password')}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button fullWidth type="submit">
|
<Button fullWidth type="submit" loading={isLoading}>
|
||||||
{t('form.buttons.submit')}
|
{t('form.buttons.submit')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user