From 3d8c646a94ef90cd26983d1b00aee00b5f4defdc Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sun, 7 Aug 2016 17:50:00 +0300 Subject: [PATCH] Display bsod for failed oauth requests --- src/components/auth/actions.js | 13 +++++++++---- src/services/api/oauth.js | 14 +++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/components/auth/actions.js b/src/components/auth/actions.js index d6f2ef4..2533458 100644 --- a/src/components/auth/actions.js +++ b/src/components/auth/actions.js @@ -4,6 +4,7 @@ import { updateUser, logout as logoutUser, acceptRules as userAcceptRules, authe import authentication from 'services/api/authentication'; import oauth from 'services/api/oauth'; import signup from 'services/api/signup'; +import dispatchBsod from 'components/ui/bsod/dispatchBsod'; export function login({login = '', password = '', rememberMe = false}) { const PASSWORD_REQUIRED = 'error.password_required'; @@ -166,16 +167,20 @@ export function oAuthComplete(params = {}) { }, (resp) => { if (resp.acceptRequired) { dispatch(requirePermissionsAccept()); - } - return handleOauthParamsValidation(resp); + return Promise.reject(resp); + } else { + return handleOauthParamsValidation(resp); + } }) ); } function handleOauthParamsValidation(resp = {}) { - /* eslint no-alert: "off" */ - resp.userMessage && alert(resp.userMessage); + dispatchBsod(); + + // eslint-disable-next-line no-alert + resp.userMessage && setTimeout(() => alert(resp.userMessage), 500); // 500 ms to allow re-render return Promise.reject(resp); } diff --git a/src/services/api/oauth.js b/src/services/api/oauth.js index d9eda59..3015ae3 100644 --- a/src/services/api/oauth.js +++ b/src/services/api/oauth.js @@ -51,19 +51,15 @@ function getOAuthRequest(oauthData) { } function handleOauthParamsValidation(resp = {}) { - let userMessage; - if (resp.statusCode === 400 && resp.error === 'invalid_request') { - userMessage = `Invalid request (${resp.parameter} required).`; + resp.userMessage = `Invalid request (${resp.parameter} required).`; } else if (resp.statusCode === 400 && resp.error === 'unsupported_response_type') { - userMessage = `Invalid response type '${resp.parameter}'.`; + resp.userMessage = `Invalid response type '${resp.parameter}'.`; } else if (resp.statusCode === 400 && resp.error === 'invalid_scope') { - userMessage = `Invalid scope '${resp.parameter}'.`; + resp.userMessage = `Invalid scope '${resp.parameter}'.`; } else if (resp.statusCode === 401 && resp.error === 'invalid_client') { - userMessage = 'Can not find application you are trying to authorize.'; - } else { - return; + resp.userMessage = 'Can not find application you are trying to authorize.'; } - return Promise.reject(userMessage); + return Promise.reject(resp); }