From 85330790dc68430c1a8834daa4390b20419fd5c9 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Sun, 5 Jul 2020 12:44:41 +0530 Subject: [PATCH] Fix: app crash on no accounts case (#191) --- src/actions/auth.js | 14 ++++++++++---- src/i18n/en.json | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/actions/auth.js b/src/actions/auth.js index 1055c5bd2..1fc1f1207 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -21,10 +21,16 @@ export const doLogin = ({ email, password }) => async (dispatch) => { dispatch({ type: LOGIN }); const response = await axios.post('auth/sign_in', { email, password }); const { data } = response.data; - const { name: username, id } = data; - Sentry.setUser({ email, username, id }); - dispatch({ type: SET_AUTH_HEADER, payload: response.headers }); - dispatch({ type: LOGIN_SUCCESS, payload: data }); + const { name: username, id, account_id } = data; + // Check user has any account + if (account_id) { + Sentry.setUser({ email, username, id }); + dispatch({ type: SET_AUTH_HEADER, payload: response.headers }); + dispatch({ type: LOGIN_SUCCESS, payload: data }); + } else { + showToast({ message: I18n.t('ERRORS.NO_ACCOUNTS_MESSAGE') }); + dispatch({ type: LOGIN_ERROR, payload: '' }); + } } catch (error) { if (error && error.status === 401) { showToast({ message: I18n.t('ERRORS.AUTH') }); diff --git a/src/i18n/en.json b/src/i18n/en.json index 3842b9a7a..814d5bd3a 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -89,7 +89,8 @@ "COMMON_ERROR": "Could not connect to Woot Server, Please try again later", "OfFLINE": "You must connect to Wi-fi or a cellular network to get online again", "CANNOT_FETCH": "There was an error fetching the information, please try again", - "AUTH": "Username / Password Incorrect. Please try again" + "AUTH": "Username / Password Incorrect. Please try again", + "NO_ACCOUNTS_MESSAGE": "You don't have access to any chatwoot accounts" }, "SUCCESS": { "AUTH": "Login Successful"