Merge pull request #5076 from lbryio/sync-embed-auth
Prevent multiple embeds from creating new users
This commit is contained in:
commit
dc679add87
1 changed files with 33 additions and 2 deletions
|
@ -6,6 +6,8 @@ import { doToast } from 'redux/actions/notifications';
|
||||||
import rewards from 'rewards';
|
import rewards from 'rewards';
|
||||||
import { Lbryio } from 'lbryinc';
|
import { Lbryio } from 'lbryinc';
|
||||||
import { DOMAIN } from 'config';
|
import { DOMAIN } from 'config';
|
||||||
|
const AUTH_IN_PROGRESS = 'authInProgress';
|
||||||
|
export let sessionStorageAvailable = false;
|
||||||
|
|
||||||
export function doFetchInviteStatus(shouldCallRewardList = true) {
|
export function doFetchInviteStatus(shouldCallRewardList = true) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
|
@ -87,6 +89,32 @@ export function doInstallNewWithParams(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkAuthBusy() {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
(function waitForAuth() {
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem('test', 'available');
|
||||||
|
sessionStorage.removeItem('test');
|
||||||
|
sessionStorageAvailable = true;
|
||||||
|
} catch (e) {
|
||||||
|
if (e) {
|
||||||
|
// no session storage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!IS_WEB || !sessionStorageAvailable) {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
const inProgress = window.sessionStorage.getItem(AUTH_IN_PROGRESS);
|
||||||
|
if (!inProgress) {
|
||||||
|
window.sessionStorage.setItem(AUTH_IN_PROGRESS, 'true');
|
||||||
|
return resolve();
|
||||||
|
} else {
|
||||||
|
setTimeout(waitForAuth, 200);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Call doInstallNew separately so we don't have to pass appVersion and os_system params?
|
// TODO: Call doInstallNew separately so we don't have to pass appVersion and os_system params?
|
||||||
export function doAuthenticate(
|
export function doAuthenticate(
|
||||||
appVersion,
|
appVersion,
|
||||||
|
@ -101,9 +129,12 @@ export function doAuthenticate(
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.AUTHENTICATION_STARTED,
|
type: ACTIONS.AUTHENTICATION_STARTED,
|
||||||
});
|
});
|
||||||
|
checkAuthBusy()
|
||||||
Lbryio.authenticate(DOMAIN, window.navigator.language.slice(0, 2) || 'en')
|
.then(() => {
|
||||||
|
return Lbryio.authenticate(DOMAIN, window.navigator.language.slice(0, 2) || 'en');
|
||||||
|
})
|
||||||
.then(user => {
|
.then(user => {
|
||||||
|
if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);
|
||||||
Lbryio.getAuthToken().then(token => {
|
Lbryio.getAuthToken().then(token => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.AUTHENTICATION_SUCCESS,
|
type: ACTIONS.AUTHENTICATION_SUCCESS,
|
||||||
|
|
Loading…
Reference in a new issue