From d2dad4dd85cba1a70eff3fb326c250a52687821c Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Fri, 3 Apr 2020 17:27:02 +0300 Subject: [PATCH] check if FB is defined --- src/routes/Intro/Intro.js | 64 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js index c66922272..f9e5ebc24 100644 --- a/src/routes/Intro/Intro.js +++ b/src/routes/Intro/Intro.js @@ -75,39 +75,41 @@ const Intro = ({ queryParams }) => { } ); const loginWithFacebook = React.useCallback(() => { - 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.dispatch({ - action: 'Ctx', - args: { - action: 'Authenticate', - args: { - type: 'Login', - email: user.email, - password: user.fbLoginToken - } + 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.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) }); }); - }) - .catch((err = {}) => { - dispatch({ type: 'error', error: err.message || JSON.stringify(err) }); - }); - } else { - dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' }); - } - }); + } else { + dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' }); + } + }); + } }, []); const loginWithEmail = React.useCallback(() => { if (typeof state.email !== 'string' || state.email.length === 0 || !emailRef.current.validity.valid) {