Skip to content

Commit

Permalink
Fix: app crash on no accounts case (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Jul 5, 2020
1 parent bd27e2f commit 8533079
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/actions/auth.js
Expand Up @@ -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') });
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en.json
Expand Up @@ -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"
Expand Down

0 comments on commit 8533079

Please sign in to comment.