diff --git a/src/LoginGate.tsx b/src/LoginGate.tsx index 9758138..4935b7d 100644 --- a/src/LoginGate.tsx +++ b/src/LoginGate.tsx @@ -12,7 +12,7 @@ import LoginForm from './components/LoginForm'; import EncryptionLoginForm from './components/EncryptionLoginForm'; import { store, StoreState, CredentialsDataRemote } from './store'; -import { deriveKey, fetchCredentials, fetchUserInfo } from './store/actions'; +import { deriveKey, fetchCredentials, fetchUserInfo, logout } from './store/actions'; import * as EteSync from 'etesync'; import * as C from './constants'; @@ -35,8 +35,14 @@ function EncryptionPart(props: { credentials: CredentialsDataRemote }) { setUserInfo(fetchedUserInfo.payload); }).catch((e: Error) => { // Do nothing. - if ((e instanceof EteSync.HTTPError) && (e.status !== 404)) { - setError(e); + if (e instanceof EteSync.HTTPError) { + if (e.status === 404) { + // Do nothing + } else if (e.status === 401) { + store.dispatch(logout(credentials)); + } else { + setError(e); + } } }).finally(() => { setFetched(true); diff --git a/src/store/actions.ts b/src/store/actions.ts index 72be410..0730ec0 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -6,7 +6,7 @@ import { Action, createAction, createActions } from 'redux-actions'; import * as EteSync from 'etesync'; import { UserInfo } from 'etesync'; -import { CredentialsData, EntriesData, SettingsType } from './'; +import { CredentialsData, CredentialsDataRemote, EntriesData, SettingsType } from './'; export const { fetchCredentials } = createActions({ FETCH_CREDENTIALS: (username: string, password: string, server: string) => { @@ -34,7 +34,7 @@ export const { fetchCredentials } = createActions({ export const logout = createAction( 'LOGOUT', - (etesync: CredentialsData) => { + (etesync: CredentialsDataRemote) => { (async () => { const authenticator = new EteSync.Authenticator(etesync.serviceApiUrl); try {