Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: show error message on failed two-factor auth

Ammar Ahmed883667b411fb
diff --git a/apps/mobile/app/components/auth/two-factor.tsx b/apps/mobile/app/components/auth/two-factor.tsx
index cc9135890..d1d990f6f 100644
--- a/apps/mobile/app/components/auth/two-factor.tsx
+++ b/apps/mobile/app/components/auth/two-factor.tsx
@@ -35,6 +35,9 @@ import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
import { DefaultAppStyles } from "../../utils/styles";
import { presentDialog } from "../dialog/functions";
+import { Notice } from "../ui/notice";
+import AppIcon from "../ui/AppIcon";
+import Clipboard from "@react-native-clipboard/clipboard";
type MFAInfo = {
primaryMethod: string;
@@ -52,7 +55,8 @@ const TwoFactorVerification = ({
method: string;
code: string;
},
- callback: (result: any) => void
+ callback: (result: any) => void,
+ onerror: (e: Error) => void
) => Promise<void>;
mfaInfo: MFAInfo;
onCancel: () => void;
@@ -70,11 +74,13 @@ const TwoFactorVerification = ({
const [loading, setLoading] = useState(false);
const inputRef = useRef<TextInput>(null);
const [sending, setSending] = useState(false);
+ const [error, setError] = useState<Error | undefined>(undefined)
const onNext = async () => {
if (!code.current || code.current.length < 6 || !currentMethod.method)
return;
setLoading(true);
+ setError(undefined);
inputRef.current?.blur();
await onMfaLogin(
{
@@ -86,6 +92,9 @@ const TwoFactorVerification = ({
eSendEvent(eCloseSimpleDialog, "two_factor_verify");
}
setLoading(false);
+ },
+ (e) => {
+ setError(e);
}
);
setLoading(false);
@@ -252,7 +261,7 @@ const TwoFactorVerification = ({
}
enablesReturnKeyAutomatically
containerStyle={{
- minWidth: "50%"
+ minWidth :"50%"
}}
wrapperStyle={{
height: 60
@@ -284,6 +293,16 @@ const TwoFactorVerification = ({
onPress={onRequestSecondaryMethod}
height={30}
/>
+
+ {
+ error ? <Paragraph numberOfLines={4} onPress={() => {
+
+ }} color={colors.error.accent} style={{
+ textAlign: "center"
+ }}>
+ <AppIcon color={colors.error.accent} name="alert-circle-outline" size={AppFontSize.sm - 1} /> {error?.message}
+ </Paragraph> : null
+ }
</>
) : (
<>
@@ -338,7 +357,8 @@ TwoFactorVerification.present = (
method: string;
code: string;
},
- callback: (result: any) => void
+ callback: (result: any) => void,
+ onerror: (e: Error) => void
) => Promise<void>,
data: MFAInfo,
onCancel: () => void,
diff --git a/apps/mobile/app/components/auth/use-login.ts b/apps/mobile/app/components/auth/use-login.ts
index f79fb3e78..47ac8bb96 100644
--- a/apps/mobile/app/components/auth/use-login.ts
+++ b/apps/mobile/app/components/auth/use-login.ts
@@ -81,7 +81,7 @@ export const useLogin = (
if (mfaInfo) {
TwoFactorVerification.present(
- async (mfa: any, callback: (success: boolean) => void) => {
+ async (mfa: any, callback: (success: boolean) => void, onerror: (e: Error) => void) => {
try {
const success = await db.user.authenticateMultiFactorCode(
mfa.code,
@@ -103,6 +103,9 @@ export const useLogin = (
eSendEvent(eCloseSimpleDialog, "two_factor_verify");
setLoading(false);
setStep(LoginSteps.emailAuth);
+ ToastManager.error(new Error("Token expired, try logging in again"));
+ } else {
+ onerror(e as Error);
}
}
},