inline statusChangeCallback func

This commit is contained in:
svetlagasheva 2019-11-11 10:55:38 +02:00
parent 823994f096
commit 2bcf42b601

View file

@ -83,38 +83,35 @@ 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.error(err);
});
}
}, [state.email, state.password]);
const loginWithFacebook = React.useCallback(() => {
FB.login(function(response) {
statusChangeCallback(response);
FB.login((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(() => {
core.dispatch({
action: 'UserOp',
args: {
userOp: 'Login',
args: {
email: state.email,
password: response.authResponse.accessToken
}
}
});
})
.catch((err) => {
console.error(err);
});
}
});
}, []);
}, [state.email, state.password]);
const loginWithEmail = React.useCallback(() => {
if (typeof state.email !== 'string' || state.email.length === 0) {
dispatch({ type: 'error', error: 'Invalid email' });