mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
check if FB is defined
This commit is contained in:
parent
7729c3ae0f
commit
d2dad4dd85
1 changed files with 33 additions and 31 deletions
|
|
@ -75,39 +75,41 @@ const Intro = ({ queryParams }) => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const loginWithFacebook = React.useCallback(() => {
|
const loginWithFacebook = React.useCallback(() => {
|
||||||
FB.login((response) => {
|
if (typeof FB !== 'undefined') {
|
||||||
if (response.status === 'connected') {
|
FB.login((response) => {
|
||||||
fetch('https://www.strem.io/fb-login-with-token/' + encodeURIComponent(response.authResponse.accessToken), { timeout: 10 * 60 * 1000 })
|
if (response.status === 'connected') {
|
||||||
.then((resp) => {
|
fetch('https://www.strem.io/fb-login-with-token/' + encodeURIComponent(response.authResponse.accessToken), { timeout: 10 * 60 * 1000 })
|
||||||
if (resp.status < 200 || resp.status >= 300) {
|
.then((resp) => {
|
||||||
throw new Error('Login failed at getting token from Stremio with status ' + resp.status);
|
if (resp.status < 200 || resp.status >= 300) {
|
||||||
} else {
|
throw new Error('Login failed at getting token from Stremio with status ' + resp.status);
|
||||||
return resp.json();
|
} 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.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) });
|
||||||
});
|
});
|
||||||
})
|
} else {
|
||||||
.catch((err = {}) => {
|
dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' });
|
||||||
dispatch({ type: 'error', error: err.message || JSON.stringify(err) });
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
dispatch({ type: 'error', error: 'Login failed at getting token from Facebook' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
const loginWithEmail = React.useCallback(() => {
|
const loginWithEmail = React.useCallback(() => {
|
||||||
if (typeof state.email !== 'string' || state.email.length === 0 || !emailRef.current.validity.valid) {
|
if (typeof state.email !== 'string' || state.email.length === 0 || !emailRef.current.validity.valid) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue