From 8d058035fc1ee072ebf4a3c151c4fc6e9ec27f97 Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Fri, 2 Oct 2020 12:56:45 +0300 Subject: [PATCH] facebook login ux improved --- src/routes/Intro/Intro.js | 68 +++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js index a50b24d09..072af1fd8 100644 --- a/src/routes/Intro/Intro.js +++ b/src/routes/Intro/Intro.js @@ -77,41 +77,41 @@ const Intro = ({ queryParams }) => { } ); const loginWithFacebook = React.useCallback(() => { - if (typeof FB !== 'undefined') { - FB.login((response) => { - if (response.status === 'connected') { - fetch('https://www.strem.io/fb-login-with-token/' + encodeURIComponent(response.authResponse.accessToken), { timeout: 10 * 60 * 1000 }) - .then((resp) => { - if (resp.status < 200 || resp.status >= 300) { - throw new Error('Login failed at getting token from Stremio with status ' + resp.status); - } else { - return resp.json(); - } - }) - .then(({ user }) => { - if (!user || typeof user.fbLoginToken !== 'string' || typeof user.email !== 'string') { - throw new Error('Login failed at getting token from Stremio'); - } - core.transport.dispatch({ - action: 'Ctx', - args: { - action: 'Authenticate', - args: { - type: 'Login', - email: user.email, - password: user.fbLoginToken - } - } - }); - }) - .catch((err = {}) => { - dispatch({ type: 'error', error: err.message || JSON.stringify(err) }); - }); - } else { - dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' }); - } - }); + if (typeof FB === 'undefined') { + dispatch({ type: 'error', error: 'Failed to connect to Facebook' }); + return; } + + openLoaderModal(); + FB.login((resp) => { + if (!resp || !resp.authResponse || typeof resp.authResponse.accessToken !== 'string' || resp.status !== 'connected') { + dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' }); + return; + } + + fetch('https://www.strem.io/fb-login-with-token/' + encodeURIComponent(resp.authResponse.accessToken)) + .then((resp) => resp.json()) + .then(({ user } = {}) => { + if (!user || typeof user.email !== 'string' || typeof user.fbLoginToken !== 'string') { + throw new Error('Login failed at getting token from Stremio'); + } + + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'Authenticate', + args: { + type: 'Login', + email: user.email, + password: user.fbLoginToken + } + } + }); + }) + .catch((err = {}) => { + dispatch({ type: 'error', error: err.message || JSON.stringify(err) }); + }); + }); }, []); const loginWithEmail = React.useCallback(() => { if (typeof state.email !== 'string' || state.email.length === 0 || !emailRef.current.validity.valid) {