Skip to content

Commit

Permalink
fix(core): prevent frequent sign-in
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Mar 27, 2024
1 parent d4c7d58 commit eaf0e1b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ export const SignInWithPassword: FC<AuthPanelProps> = ({
isMutating: sendingEmail,
} = useAuth();
const [verifyToken, challenge] = useCaptcha();
const [isLoading, setIsLoading] = useState(false);

const onSignIn = useAsyncCallback(async () => {
if (isLoading) return;
setIsLoading(true);

const res = await signInCloud('credentials', {
email,
password,
}).catch(console.error);

if (!res?.ok) {
return setPasswordError(true);
if (res?.ok) {
await reload();
onSignedIn?.();
} else {
setPasswordError(true);
}

await reload();
onSignedIn?.();
}, [email, password, onSignedIn, reload]);
setIsLoading(false);
}, [email, password, isLoading, onSignedIn, reload]);

const sendMagicLink = useAsyncCallback(async () => {
if (allowSendEmail && verifyToken && !sendingEmail) {
Expand Down Expand Up @@ -134,6 +140,7 @@ export const SignInWithPassword: FC<AuthPanelProps> = ({
type="primary"
size="extraLarge"
style={{ width: '100%' }}
disabled={isLoading}
onClick={onSignIn}
>
{t['com.affine.auth.sign.in']()}
Expand Down

0 comments on commit eaf0e1b

Please sign in to comment.