diff --git a/src/pages/auth/login.tsx b/src/pages/auth/login.tsx index 59d257dc0..8da51bfcf 100644 --- a/src/pages/auth/login.tsx +++ b/src/pages/auth/login.tsx @@ -18,6 +18,7 @@ import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import Head from 'next/head'; import { useRouter } from 'next/router'; +import { useState } from 'react'; import { z } from 'zod'; import { getServerAuthSession } from '~/server/auth'; import { useI18nZodResolver } from '~/utils/i18n-zod-resolver'; @@ -29,6 +30,8 @@ export default function LoginPage() { const { t } = useTranslation(['authentication/login']); const queryParams = useRouter().query as { error?: 'CredentialsSignin' | (string & {}) }; const { i18nZodResolver } = useI18nZodResolver(); + const router = useRouter(); + const [isLoading, setIsLoading] = useState(false); const form = useForm>({ validateInputOnChange: true, @@ -37,11 +40,18 @@ export default function LoginPage() { }); const handleSubmit = (values: z.infer) => { + setIsLoading(true); signIn('credentials', { redirect: false, name: values.name, password: values.password, callbackUrl: '/', + }).then((response) => { + if (!response?.ok) { + setIsLoading(false); + return; + } + router.push('/manage'); }); }; @@ -75,7 +85,7 @@ export default function LoginPage() { {...form.getInputProps('password')} /> -