fix(core): prevent frequent sign-in (#6339)
This commit is contained in:
@@ -35,20 +35,26 @@ export const SignInWithPassword: FC<AuthPanelProps> = ({
|
|||||||
isMutating: sendingEmail,
|
isMutating: sendingEmail,
|
||||||
} = useAuth();
|
} = useAuth();
|
||||||
const [verifyToken, challenge] = useCaptcha();
|
const [verifyToken, challenge] = useCaptcha();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const onSignIn = useAsyncCallback(async () => {
|
const onSignIn = useAsyncCallback(async () => {
|
||||||
|
if (isLoading) return;
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
const res = await signInCloud('credentials', {
|
const res = await signInCloud('credentials', {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
|
|
||||||
if (!res?.ok) {
|
if (res?.ok) {
|
||||||
return setPasswordError(true);
|
await reload();
|
||||||
|
onSignedIn?.();
|
||||||
|
} else {
|
||||||
|
setPasswordError(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await reload();
|
setIsLoading(false);
|
||||||
onSignedIn?.();
|
}, [email, password, isLoading, onSignedIn, reload]);
|
||||||
}, [email, password, onSignedIn, reload]);
|
|
||||||
|
|
||||||
const sendMagicLink = useAsyncCallback(async () => {
|
const sendMagicLink = useAsyncCallback(async () => {
|
||||||
if (allowSendEmail && verifyToken && !sendingEmail) {
|
if (allowSendEmail && verifyToken && !sendingEmail) {
|
||||||
@@ -134,6 +140,7 @@ export const SignInWithPassword: FC<AuthPanelProps> = ({
|
|||||||
type="primary"
|
type="primary"
|
||||||
size="extraLarge"
|
size="extraLarge"
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
|
disabled={isLoading}
|
||||||
onClick={onSignIn}
|
onClick={onSignIn}
|
||||||
>
|
>
|
||||||
{t['com.affine.auth.sign.in']()}
|
{t['com.affine.auth.sign.in']()}
|
||||||
|
|||||||
Reference in New Issue
Block a user