diff --git a/src/index.html b/src/index.html index 55a8694ad..919a94851 100755 --- a/src/index.html +++ b/src/index.html @@ -12,6 +12,17 @@
+ + diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js index 1989cf6ea..062198661 100644 --- a/src/routes/Intro/Intro.js +++ b/src/routes/Intro/Intro.js @@ -82,8 +82,39 @@ const Intro = ({ queryParams }) => { core.off('Event', onEvent); }; }, []); + const statusChangeCallback = React.useCallback((response) => { + if (response.status === 'connected') { + fetch(baseUrl + "/fb-login-with-token/" + encodeURIComponent(response.authResponse.accessToken), { timeout: 10 * 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(function() { + core.dispatch({ + action: 'UserOp', + args: { + userOp: 'Login', + args: { + email: state.email, + password: response.authResponse.accessToken + } + } + }); + }) + .catch(function(err) { + console.log(err); + }); + } else { + console.log('Please log into this app.'); + } + }, [state.email, state.password]); const loginWithFacebook = React.useCallback(() => { - alert('TODO: Facebook login'); + FB.login(function(response) { + statusChangeCallback(response); + }); }, []); const loginWithEmail = React.useCallback(() => { if (typeof state.email !== 'string' || state.email.length === 0) {