From bb6cdd4b71fa82912cf46d710f389bc963908087 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 8 Sep 2021 11:08:22 -0500 Subject: [PATCH] Mastodon: return a friendlier login error than 'invalid_grant' --- app/soapbox/actions/auth.js | 10 +++++++++- app/soapbox/actions/oauth.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index ee496450b..78c144a37 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -163,10 +163,18 @@ export function logIn(intl, username, password) { return dispatch(createUserToken(username, password)); }).catch(error => { if (error.response.data.error === 'mfa_required') { + // If MFA is required, throw the error and handle it in the component. throw error; - } else if(error.response.data.error) { + } else if (error.response.data.error === 'invalid_grant') { + // Mastodon returns this user-unfriendly error as a catch-all + // for everything from "bad request" to "wrong password". + // Assume our code is correct and it's a wrong password. + dispatch(snackbar.error(intl.formatMessage(messages.invalidCredentials))); + } else if (error.response.data.error) { + // If the backend returns an error, display it. dispatch(snackbar.error(error.response.data.error)); } else { + // Return "wrong password" message. dispatch(snackbar.error(intl.formatMessage(messages.invalidCredentials))); } throw error; diff --git a/app/soapbox/actions/oauth.js b/app/soapbox/actions/oauth.js index fe25d34f0..9662972a8 100644 --- a/app/soapbox/actions/oauth.js +++ b/app/soapbox/actions/oauth.js @@ -23,7 +23,7 @@ export function obtainOAuthToken(params, baseURL) { dispatch({ type: OAUTH_TOKEN_CREATE_SUCCESS, params, token }); return token; }).catch(error => { - dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error }); + dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error, skipAlert: true }); throw error; }); };