From 31da9e24acfce9655420041f3a06534071588f82 Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Thu, 6 Feb 2020 16:43:32 +0200 Subject: [PATCH] facebook login implemented --- src/routes/Intro/Intro.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js index 223294e12..7f6b6836c 100644 --- a/src/routes/Intro/Intro.js +++ b/src/routes/Intro/Intro.js @@ -89,7 +89,7 @@ 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 * 1000 }) + 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); @@ -97,22 +97,30 @@ const Intro = ({ queryParams }) => { return resp.json(); } }) - .then(() => { + .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: 'UserOp', + action: 'Ctx', args: { - userOp: 'Login', + action: 'Authenticate', args: { - email: state.email, - password: response.authResponse.accessToken + type: 'Login', + email: user.email, + password: user.fbLoginToken } } }); }) - .catch(() => { }); + .catch((err = {}) => { + dispatch({ type: 'error', error: err.message || JSON.stringify(err) }); + }); + } else { + dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' }); } }); - }, [state.email, state.password]); + }, []); const loginWithEmail = React.useCallback(() => { if (typeof state.email !== 'string' || state.email.length === 0) { dispatch({ type: 'error', error: 'Invalid email' });