🐛 fix(auth): Refactor user authentication forms to remove global store dependency and improve type handling
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
||||
NEXT_PUBLIC_DEFAULT_USER_EMAIL,
|
||||
NEXT_PUBLIC_DEFAULT_USER_PASSWORD,
|
||||
} from '@/config/constants';
|
||||
import useGlobalStore from '@/config/use-global';
|
||||
import { checkUser, resetPassword, userLogin, userRegister } from '@/services/common/auth';
|
||||
import { getRedirectUrl, setAuthorization } from '@/utils/common';
|
||||
import { useTranslations } from 'next-intl';
|
||||
@@ -18,8 +17,6 @@ import UserResetForm from './user-reset-form';
|
||||
|
||||
export default function UserAuthForm() {
|
||||
const t = useTranslations('auth');
|
||||
const { common } = useGlobalStore();
|
||||
const { register } = common;
|
||||
const router = useRouter();
|
||||
const [type, setType] = useState<'login' | 'register' | 'reset'>();
|
||||
const [loading, startTransition] = useTransition();
|
||||
|
||||
@@ -8,30 +8,21 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
|
||||
interface UserCheckFormProps {
|
||||
loading?: boolean;
|
||||
onSubmit: (data: any) => void;
|
||||
initialValues: any;
|
||||
}
|
||||
|
||||
export default function UserCheckForm({
|
||||
loading,
|
||||
onSubmit,
|
||||
initialValues,
|
||||
}: {
|
||||
loading?: boolean;
|
||||
onSubmit: (data: any) => void;
|
||||
initialValues: any;
|
||||
}) {
|
||||
}: Readonly<UserCheckFormProps>) {
|
||||
const t = useTranslations('auth.check');
|
||||
// const { common } = useGlobalStore();
|
||||
// const { register } = common;
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email(t('email')),
|
||||
// .refine(
|
||||
// (email) => {
|
||||
// if (!register.enable_email_domain_suffix) return true;
|
||||
// const domain = email.split('@')[1] as string;
|
||||
// return register.email_domain_suffix_list.split('\n').includes(domain);
|
||||
// },
|
||||
// {
|
||||
// message: t('whitelist'),
|
||||
// },
|
||||
// ),
|
||||
});
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
@@ -61,7 +52,7 @@ export default function UserCheckForm({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (initialValues && initialValues.email) {
|
||||
if (initialValues?.email) {
|
||||
handleEmailChange(initialValues.email);
|
||||
}
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user