Skip to content

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

fix logout

Ammar Ahmed7b694df278dd
diff --git a/apps/mobile/src/components/auth/changepassword.js b/apps/mobile/src/components/auth/changepassword.js
index f134fe2aa..60d28beb4 100644
--- a/apps/mobile/src/components/auth/changepassword.js
+++ b/apps/mobile/src/components/auth/changepassword.js
@@ -23,7 +23,7 @@ export const ChangePassword = () => {
const user = useUserStore(state => state.user);
const changePassword = async () => {
- if (!user.isEmailConfirmed) {
+ if (!user?.isEmailConfirmed) {
ToastEvent.show({
heading: 'Email not confirmed',
message: 'Please confirm your email to change account password',
diff --git a/apps/mobile/src/components/auth/login.js b/apps/mobile/src/components/auth/login.js
index b081e7d91..c57fc560d 100644
--- a/apps/mobile/src/components/auth/login.js
+++ b/apps/mobile/src/components/auth/login.js
@@ -93,7 +93,7 @@ export const Login = ({ changeMode, welcome }) => {
hideAuth();
SettingsService.set({
sessionExpired: false,
- userEmailConfirmed: user.isEmailConfirmed
+ userEmailConfirmed: user?.isEmailConfirmed
});
eSendEvent('userLoggedIn', true);
await sleep(500);
diff --git a/apps/mobile/src/components/auth/sessionexpired.js b/apps/mobile/src/components/auth/sessionexpired.js
index 72fb6fdcd..84c2ef2b8 100644
--- a/apps/mobile/src/components/auth/sessionexpired.js
+++ b/apps/mobile/src/components/auth/sessionexpired.js
@@ -124,7 +124,7 @@ export const SessionExpired = () => {
});
await SettingsService.set({
sessionExpired: false,
- userEmailConfirmed: user.isEmailConfirmed
+ userEmailConfirmed: user?.isEmailConfirmed
});
eSendEvent('userLoggedIn', true);
await sleep(500);
diff --git a/apps/mobile/src/screens/editor/tiptap/picker.js b/apps/mobile/src/screens/editor/tiptap/picker.js
index 92f44eb06..4c9314b20 100644
--- a/apps/mobile/src/screens/editor/tiptap/picker.js
+++ b/apps/mobile/src/screens/editor/tiptap/picker.js
@@ -181,7 +181,7 @@ const pick = async options => {
if (editorState().isFocused) {
editorState().isFocused = true;
}
- if (user && !PremiumService.get() && !user.isEmailConfirmed) {
+ if (user && !PremiumService.get() && !user?.isEmailConfirmed) {
PremiumService.showVerifyEmailDialog();
} else {
PremiumService.sheet();
diff --git a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
index ee09b8ac2..af339f5d9 100644
--- a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
+++ b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
@@ -66,7 +66,7 @@ const publishNote = async (editor: useEditorType) => {
return;
}
- if (!user.isEmailConfirmed) {
+ if (!user?.isEmailConfirmed) {
ToastEvent.show({
heading: 'Email not verified',
message: 'Please verify your email first.',
diff --git a/apps/mobile/src/screens/settings/settingsdata.tsx b/apps/mobile/src/screens/settings/settingsdata.tsx
index 0d9ca8988..9e5badbdf 100644
--- a/apps/mobile/src/screens/settings/settingsdata.tsx
+++ b/apps/mobile/src/screens/settings/settingsdata.tsx
@@ -262,6 +262,7 @@ export const settingsGroups: SettingSection[] = [
eSendEvent('settings-loading', true);
setImmediate(async () => {
eSendEvent(eCloseSimpleDialog);
+ Navigation.popToTop();
db.user?.logout();
setLoginMessage();
await PremiumService.setPremiumStatus();
@@ -270,14 +271,15 @@ export const settingsGroups: SettingSection[] = [
await db.init();
await clearAllStores();
SettingsService.init();
- SettingsService.set({
- introCompleted: true
- });
+ setTimeout(() => {
+ SettingsService.set({
+ introCompleted: true
+ });
+ }, 1000);
useUserStore.getState().setUser(null);
useUserStore.getState().setSyncing(false);
- console.log('HIDING');
- Navigation.goBack();
Navigation.goBack();
+ Navigation.popToTop();
eSendEvent('settings-loading', false);
});
} catch (e) {
diff --git a/apps/mobile/src/screens/settings/subscription.js b/apps/mobile/src/screens/settings/subscription.js
index f14ed1192..0eca5f064 100644
--- a/apps/mobile/src/screens/settings/subscription.js
+++ b/apps/mobile/src/screens/settings/subscription.js
@@ -19,7 +19,7 @@ export const Subscription = () => {
const subscriptionProviderInfo = SUBSCRIPTION_PROVIDER[user?.subscription?.provider];
const manageSubscription = () => {
- if (!user.isEmailConfirmed) {
+ if (!user?.isEmailConfirmed) {
PremiumService.showVerifyEmailDialog();
return;
}
@@ -62,7 +62,7 @@ export const Subscription = () => {
type="accent"
onPress={manageSubscription}
title={
- !user.isEmailConfirmed
+ !user?.isEmailConfirmed
? 'Confirm your email'
: user.subscription?.provider === 3 &&
user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED
diff --git a/apps/mobile/src/stores/useMessageStore.ts b/apps/mobile/src/stores/useMessageStore.ts
index 648880f63..f303ee560 100644
--- a/apps/mobile/src/stores/useMessageStore.ts
+++ b/apps/mobile/src/stores/useMessageStore.ts
@@ -168,11 +168,11 @@ async function shouldShowAnnouncement(announcement: Announcement) {
case 'loggedOut':
return !user;
case 'verified':
- return user.isEmailConfirmed;
+ return user?.isEmailConfirmed;
case 'loggedIn':
return !!user;
case 'unverified':
- return !user.isEmailConfirmed;
+ return !user?.isEmailConfirmed;
case 'proExpired':
return (
subStatus === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED ||
diff --git a/apps/mobile/src/utils/hooks/useAppEvents.js b/apps/mobile/src/utils/hooks/useAppEvents.js
index 151cba351..a9c98d633 100644
--- a/apps/mobile/src/utils/hooks/useAppEvents.js
+++ b/apps/mobile/src/utils/hooks/useAppEvents.js
@@ -273,7 +273,7 @@ export const useAppEvents = () => {
}
await PremiumService.setPremiumStatus();
- if (user.isEmailConfirmed && !userEmailConfirmed) {
+ if (user?.isEmailConfirmed && !userEmailConfirmed) {
setTimeout(() => {
onEmailVerified();
}, 1000);
@@ -293,7 +293,7 @@ export const useAppEvents = () => {
) {
setRecoveryKeyMessage();
}
- if (!user.isEmailConfirmed) setEmailVerifyMessage();
+ if (!user?.isEmailConfirmed) setEmailVerifyMessage();
refValues.current.isUserReady = true;
syncedOnLaunch.current = true;
@@ -349,7 +349,7 @@ export const useAppEvents = () => {
await checkIntentState();
await MMKV.removeItem('appState');
let user = await db.user.getUser();
- if (user && !user.isEmailConfirmed) {
+ if (user && !user?.isEmailConfirmed) {
try {
let user = await db.user.fetchUser();
if (user?.isEmailConfirmed) {