web: fix login form shown for split second before login

This commit is contained in:
Abdullah Atta
2023-09-13 12:42:54 +05:00
parent 74fef0d2d9
commit 83d919f06e

View File

@@ -272,6 +272,7 @@ function LoginPassword(props: BaseAuthComponentProps<"login:password">) {
type="login:password" type="login:password"
title="Your account password" title="Your account password"
subtitle={"Your password is always hashed before leaving this device."} subtitle={"Your password is always hashed before leaving this device."}
loadForever
loading={{ loading={{
title: "Logging you in", title: "Logging you in",
subtitle: "Please wait while you are authenticated." subtitle: "Please wait while you are authenticated."
@@ -806,6 +807,7 @@ type AuthFormProps<TType extends AuthRoutes> = {
loading: { title: string; subtitle: string }; loading: { title: string; subtitle: string };
type: TType; type: TType;
onSubmit: (form: AuthFormData[TType]) => Promise<void>; onSubmit: (form: AuthFormData[TType]) => Promise<void>;
loadForever?: boolean;
canSkip?: boolean; canSkip?: boolean;
children?: children?:
| React.ReactNode | React.ReactNode
@@ -813,7 +815,7 @@ type AuthFormProps<TType extends AuthRoutes> = {
}; };
export function AuthForm<T extends AuthRoutes>(props: AuthFormProps<T>) { export function AuthForm<T extends AuthRoutes>(props: AuthFormProps<T>) {
const { title, subtitle, children, canSkip } = props; const { title, subtitle, children, canSkip, loadForever } = props;
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string>(); const [error, setError] = useState<string>();
const formRef = useRef<HTMLFormElement>(null); const formRef = useRef<HTMLFormElement>(null);
@@ -838,7 +840,9 @@ export function AuthForm<T extends AuthRoutes>(props: AuthFormProps<T>) {
try { try {
setForm(form); setForm(form);
await props.onSubmit(form); await props.onSubmit(form);
if (!loadForever) setIsSubmitting(false);
} catch (e) { } catch (e) {
setIsSubmitting(false);
const error = e as Error; const error = e as Error;
if (error.message === "invalid_grant") { if (error.message === "invalid_grant") {
setError( setError(
@@ -847,8 +851,6 @@ export function AuthForm<T extends AuthRoutes>(props: AuthFormProps<T>) {
return; return;
} }
setError(error.message); setError(error.message);
} finally {
setIsSubmitting(false);
} }
}} }}
sx={{ sx={{