diff --git a/lib/boot-without-auth.tsx b/lib/boot-without-auth.tsx index b8d626ba6..bdebd52a5 100644 --- a/lib/boot-without-auth.tsx +++ b/lib/boot-without-auth.tsx @@ -44,8 +44,9 @@ class AppWithoutAuth extends Component { window.electron?.receive('appCommand', this.onAppCommand); } - componentWillUnmount() { + login(token: string, username: string, createWelcomeNote: boolean) { window.electron?.removeListener('appCommand'); + this.props.onAuth(token, username, createWelcomeNote); } onAppCommand = (event) => { @@ -76,7 +77,7 @@ class AppWithoutAuth extends Component { if (!user.access_token) { throw new Error('missing access token'); } - this.props.onAuth(user.access_token, username, false); + this.login(user.access_token, username, false); }) .catch((error: unknown) => { if ( @@ -106,7 +107,7 @@ class AppWithoutAuth extends Component { } recordEvent('user_account_created'); - this.props.onAuth(user.access_token, username, true); + this.login(user.access_token, username, true); }) .catch(() => { this.setState({ authStatus: 'unknown-error' }); @@ -115,7 +116,7 @@ class AppWithoutAuth extends Component { }; tokenLogin = (username: string, token: string) => { - this.props.onAuth(token, username, false); + this.login(token, username, false); }; render() { diff --git a/lib/boot.ts b/lib/boot.ts index 587eb8d1f..0fb0216a2 100644 --- a/lib/boot.ts +++ b/lib/boot.ts @@ -5,7 +5,6 @@ import './utils/ensure-platform-support'; import { parse } from 'cookie'; -import analytics from './analytics'; import getConfig from '../get-config'; import { boot as bootWithoutAuth } from './boot-without-auth'; import { boot as bootLoggingOut } from './logging-out'; @@ -24,8 +23,13 @@ const clearStorage = (): Promise => const settings = localStorage.getItem('simpleNote'); if (settings) { - const { accountName, ...otherSettings } = settings; - localStorage.setItem('simpleNote', otherSettings); + try { + const { accountName, ...otherSettings } = JSON.parse(settings); + localStorage.setItem('simpleNote', JSON.stringify(otherSettings)); + } catch (e) { + // pass - we only care if we can successfully do this, + // not if we fail to do it + } } Promise.all([