A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix 2fa issues
ammarahm-ed321780f94506
diff --git a/apps/mobile/src/components/auth/forgotpassword.js b/apps/mobile/src/components/auth/forgotpassword.jsindex 2b74a2861..eb6019f81 100644--- a/apps/mobile/src/components/auth/forgotpassword.js+++ b/apps/mobile/src/components/auth/forgotpassword.js@@ -1,19 +1,18 @@import React, { useRef, useState } from 'react';import { View } from 'react-native';import ActionSheet from 'react-native-actions-sheet';-import { useThemeStore } from '../../stores/theme';import { DDS } from '../../services/device-detection';import { ToastEvent } from '../../services/event-manager';+import SettingsService from '../../services/settings';+import { useThemeStore } from '../../stores/theme';import { db } from '../../utils/database';-import { MMKV } from '../../utils/database/mmkv';-import { IconButton } from '../ui/icon-button';-import { Button } from '../ui/button';import DialogHeader from '../dialog/dialog-header';+import { Button } from '../ui/button';+import { IconButton } from '../ui/icon-button';import Input from '../ui/input';import Seperator from '../ui/seperator';import Heading from '../ui/typography/heading';import Paragraph from '../ui/typography/paragraph';-import SettingsService from '../../services/settings';export const ForgotPassword = () => {const colors = useThemeStore(state => state.colors);diff --git a/apps/mobile/src/components/auth/signup.js b/apps/mobile/src/components/auth/signup.jsindex d9d6ed5de..36ff805e0 100644--- a/apps/mobile/src/components/auth/signup.js+++ b/apps/mobile/src/components/auth/signup.js@@ -177,7 +177,9 @@ export const Signup = ({ changeMode, welcome, trial }) => {autoCapitalize="none"errorMessage="Email is invalid"placeholder="Email"- onSubmit={() => {}}+ onSubmit={() => {+ passwordInputRef.current?.focus();+ }}/><Input@@ -194,6 +196,9 @@ export const Signup = ({ changeMode, welcome, trial }) => {validationType="password"autoCorrect={false}placeholder="Password"+ onSubmit={() => {+ confirmPasswordInputRef.current?.focus();+ }}/><Input@@ -212,6 +217,7 @@ export const Signup = ({ changeMode, welcome, trial }) => {customValidator={() => password.current}placeholder="Confirm password"marginBottom={5}+ onSubmit={signup}/><Paragraph size={SIZE.xs} color={colors.icon}>By signing up, you agree to our{' '}diff --git a/apps/mobile/src/components/auth/twofactor.js b/apps/mobile/src/components/auth/twofactor.jsindex 41c242f73..86a1b9b8a 100644--- a/apps/mobile/src/components/auth/twofactor.js+++ b/apps/mobile/src/components/auth/twofactor.js@@ -114,7 +114,7 @@ const TwoFactorVerification = ({ onMfaLogin, mfaInfo }) => {// TODOsetSending(true);try {- console.log('sending code');+ console.log('sending code', currentMethod.method, mfaInfo.token);await db.mfa.sendCode(currentMethod.method, mfaInfo.token);start(60);setSending(false);@@ -148,7 +148,7 @@ const TwoFactorVerification = ({ onMfaLogin, mfaInfo }) => {>{currentMethod.method? 'Two factor authentication'- : 'Other methods for two-factor authentication'}+ : 'Select methods for two-factor authentication'}</Heading><Paragraphstyle={{@@ -180,7 +180,6 @@ const TwoFactorVerification = ({ onMfaLogin, mfaInfo }) => {maxLength={currentMethod.method === 'recoveryCode' ? 8 : 6}fwdRef={inputRef}textAlign="center"- keyboardType="numeric"onChangeText={value => {code.current = value;onNext();@@ -193,6 +192,7 @@ const TwoFactorVerification = ({ onMfaLogin, mfaInfo }) => {letterSpacing: 10,width: null}}+ keyboardType={currentMethod.method === 'recoveryCode' ? 'default' : 'numeric'}containerStyle={{height: 60,borderWidth: 0,@@ -276,7 +276,8 @@ TwoFactorVerification.present = (onMfaLogin, data) => {context: 'two_factor_verify',onClose: () => {onMfaLogin();- }+ },+ disableClosing: true});};diff --git a/apps/mobile/src/components/ui/input/index.tsx b/apps/mobile/src/components/ui/input/index.tsxindex 2afae0645..44aafa2d2 100644--- a/apps/mobile/src/components/ui/input/index.tsx+++ b/apps/mobile/src/components/ui/input/index.tsx@@ -21,10 +21,11 @@ import { getElevation } from '../../../utils';import { SIZE } from '../../../utils/size';import { IconButton } from '../icon-button';import Paragraph from '../typography/paragraph';+import phone from 'phone';interface InputProps extends TextInputProps {fwdRef?: RefObject<any>;- validationType?: 'password' | 'email' | 'confirmPassword' | 'username';+ validationType?: 'password' | 'email' | 'confirmPassword' | 'username' | 'phonenumber';loading?: boolean;onSubmit?: (event: NativeSyntheticEvent<TextInputSubmitEditingEventData>) => void | undefined;onErrorCheck?: (error: boolean) => void;@@ -113,6 +114,19 @@ const Input = ({break;case 'confirmPassword':isError = customValidator && value === customValidator();+ break;+ case 'phonenumber':+ // eslint-disable-next-line no-case-declarations+ let result = phone(value, {+ strictDetection: true,+ validateMobilePrefix: true+ });+ console.log(result);+ isError = result.isValid;+ if (result.isValid) {+ onChangeText && onChangeText(result.phoneNumber);+ }+break;}@@ -135,6 +149,7 @@ const Input = ({const onChange = (value: string) => {onChangeText && onChangeText(value);+ setShowError(false);validate(value);};@@ -201,7 +216,7 @@ const Input = ({editable={!loading}onChangeText={onChange}onBlur={onBlur}- keyboardType={validationType === 'email' ? 'email-address' : 'default'}+ keyboardType={validationType === 'email' ? 'email-address' : restProps.keyboardType}importantForAutofill="yes"importantForAccessibility="yes"keyboardAppearance={colors.night ? 'dark' : 'light'}diff --git a/apps/mobile/src/screens/settings/2fa.tsx b/apps/mobile/src/screens/settings/2fa.tsxindex a0c1f895b..49c7bcf4d 100644--- a/apps/mobile/src/screens/settings/2fa.tsx+++ b/apps/mobile/src/screens/settings/2fa.tsx@@ -1,6 +1,6 @@import Clipboard from '@react-native-clipboard/clipboard';import React, { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';-import { ActivityIndicator, Platform, View } from 'react-native';+import { ActivityIndicator, Linking, Platform, View } from 'react-native';import { FlatList } from 'react-native-gesture-handler';import * as ScopedStorage from 'react-native-scoped-storage';import RNFetchBlob from 'rn-fetch-blob';@@ -15,7 +15,7 @@ import { SvgView } from '../../components/ui/svg';import Heading from '../../components/ui/typography/heading';import Paragraph from '../../components/ui/typography/paragraph';import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';-import { useSettingStore, useUserStore } from '../../stores/stores';+import { useUserStore } from '../../stores/stores';import { ThemeStore, useThemeStore } from '../../stores/theme';import { db } from '../../utils/database';import Storage from '../../utils/database/storage';@@ -32,7 +32,9 @@ const TwoFactorAuth = ({ isSheet }: { isSheet: boolean }) => {const user = useUserStore(state => state.user);const enable2fa = () => {- MFASheet.present();+ verifyUser('global', async () => {+ MFASheet.present();+ });};const disable2fa = () => {@@ -50,7 +52,9 @@ const TwoFactorAuth = ({ isSheet }: { isSheet: boolean }) => {? 'Reconfigure fallback 2FA method': 'Add fallback 2FA method',func: () => {- MFASheet.present(true);+ verifyUser('global', async () => {+ MFASheet.present(true);+ });},desc: 'You can use fallback 2FA method incase you are unable to login via primary method'},@@ -64,14 +68,14 @@ const TwoFactorAuth = ({ isSheet }: { isSheet: boolean }) => {desc: 'View and save recovery codes for to recover your account'},{- name: 'Disable Two Factor Authentication',+ name: 'Disable two-factor authentication',func: disable2fa,desc: 'Decreased security for your account'}]: [{- name: 'Enable Two Factor Authentication',+ name: 'Enable two-factor authentication',func: enable2fa,desc: 'Increased security for your account'}@@ -219,6 +223,7 @@ const MFASetup = ({ method, onSuccess, setStep, recovery }: MFAStepProps) => {const [loading, setLoading] = useState(method?.id === 'app' ? true : false);const [enabling, setEnabling] = useState(false);const [sending, setSending] = useState(false);+ const [error, setError] = useState(false);useEffect(() => {if (method?.id === 'app') {@@ -262,9 +267,14 @@ const MFASetup = ({ method, onSuccess, setStep, recovery }: MFAStepProps) => {const onSendCode = async () => {console.log('send code');+ if (error) return;if (!method || sending) return;if (method.id === 'app' && authenticatorDetails.sharedKey) {Clipboard.setString(authenticatorDetails.sharedKey);+ if (authenticatorDetails.authenticatorUri) {+ await Linking.openURL(authenticatorDetails.authenticatorUri).catch(console.log);+ }+ToastEvent.show({heading: `Code copied!`,type: 'success',@@ -339,23 +349,32 @@ const MFASetup = ({ method, onSuccess, setStep, recovery }: MFAStepProps) => {? authenticatorDetails?.sharedKey || '': undefined}- onChangeText={value => (phoneNumber.current = value)}+ multiline={method.id === 'app'}+ onChangeText={value => {+ phoneNumber.current = value;+ }}placeholder={method?.id === 'email' ? 'Enter email address' : '+1234567890'}onSubmit={() => {onSendCode();}}+ onErrorCheck={e => setError(e)}+ validationType="phonenumber"+ keyboardType="phone-pad"+ errorMessage="Please enter a valid phone number with country code"buttons={- <Button- onPress={onSendCode}- loading={sending}- title={- sending- ? null- : method.id === 'app'- ? 'Copy'- : `${seconds ? `Resend code in (${seconds})` : 'Send code'}`- }- />+ error ? null : (+ <Button+ onPress={onSendCode}+ loading={sending}+ title={+ sending+ ? null+ : method.id === 'app'+ ? 'Copy'+ : `${seconds ? `Resend code in (${seconds})` : 'Send code'}`+ }+ />+ )}/>@@ -595,7 +614,7 @@ const MFASuccess = ({ recovery }: MFAStepProps) => {<Seperator /><DialogHeadercentered={true}- title={recovery ? 'Secondary method for 2FA enabled' : 'Two-factor authentication enabled!'}+ title={recovery ? 'Fallback method for 2FA enabled' : 'Two-factor authentication enabled!'}paragraph="Your account is now 100% secure against unauthorized logins."padding={12}/>diff --git a/apps/mobile/src/services/validation.js b/apps/mobile/src/services/validation.jsindex 06fec7e5e..796b64153 100644--- a/apps/mobile/src/services/validation.js+++ b/apps/mobile/src/services/validation.js@@ -9,7 +9,8 @@ export function validateEmail(email) {}export const ERRORS_LIST = {- SHORT_PASS: 'Atleast 8 characters'+ SHORT_PASS: 'Atleast 8 characters',+ error: null};export function validatePass(password) {