login with fb implemented

This commit is contained in:
svetlagasheva 2019-11-08 15:59:45 +02:00
parent 1dc37fc934
commit 8718d868bf
2 changed files with 43 additions and 1 deletions

View file

@ -12,6 +12,17 @@
<body>
<div id="app"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1537119779906825',
autoLogAppEvents : false,
xfbml : false,
version : 'v2.5'
});
};
</script>
<script async defer src="https://connect.facebook.net/en_US/sdk.js"></script>
<script type="text/javascript">
<%= compilation.assets['main.js'].source() %>
</script>

View file

@ -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) {