doAuth changes

This commit is contained in:
jessop 2020-09-02 09:57:46 -04:00
parent b96561477a
commit d35a129ee0
4 changed files with 137 additions and 107 deletions

77
dist/bundle.es.js vendored
View file

@ -322,6 +322,10 @@ Lbryio.authenticate = () => {
Lbryio.getAuthToken().then(token => {
if (!token || token.length > 60) {
return false;
}
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(token);
} // check that token works
@ -331,46 +335,44 @@ Lbryio.authenticate = () => {
return user;
}
return lbryRedux.Lbry.status().then(status => {
if (Lbryio.overrides.setAuthToken) {
return Lbryio.overrides.setAuthToken(status);
} // simply call the logic to create a new user, and obtain the auth token
return lbryRedux.Lbry.status().then(status => // simply call the logic to create a new user, and obtain the auth token
new Promise((res, rej) => {
Lbryio.call('user', 'new', {
auth_token: '',
language: 'en',
app_id: status.installation_id
}, 'post').then(response => {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
const {
store
} = window;
return new Promise((res, rej) => {
Lbryio.call('user', 'new', {
auth_token: '',
language: 'en',
app_id: status.installation_id
}, 'post').then(response => {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(response.auth_token);
}
const {
store
} = window;
if (store) {
store.dispatch({
type: GENERATE_AUTH_TOKEN_SUCCESS,
data: {
authToken: response.auth_token
}
});
}
if (store) {
store.dispatch({
type: GENERATE_AUTH_TOKEN_SUCCESS,
data: {
authToken: response.auth_token
}
});
}
Lbryio.authToken = response.auth_token;
return res(response);
}).catch(error => rej(error));
})).then(newUser => {
if (!newUser) {
return Lbryio.getCurrentUser();
}
Lbryio.authToken = response.auth_token;
res(response);
}).catch(error => rej(error));
});
return newUser;
});
}).then(user => {
if (!user) {
return Lbryio.getCurrentUser();
}
return user;
}).then(resolve, reject);
});
}
@ -824,6 +826,7 @@ function doSetDefaultAccount(success, failure) {
};
}
function doSetSync(oldHash, newHash, data) {
console.log('doSetSync newhash, data', newHash, data);
return dispatch => {
dispatch({
type: SET_SYNC_STARTED
@ -862,6 +865,7 @@ function doGetSync(passedPassword, callback) {
throw new Error('Second argument passed to "doGetSync" must be a function');
}
console.log('callback hasnewdata', hasNewData);
callback(error, hasNewData);
}
}
@ -891,6 +895,7 @@ function doGetSync(passedPassword, callback) {
hash
}, 'post')).then(response => {
const syncHash = response.hash;
console.log('hash response', response);
data.syncHash = syncHash;
data.syncData = response.data;
data.changed = response.changed;
@ -904,7 +909,10 @@ function doGetSync(passedPassword, callback) {
});
}
}).then(response => {
console.log('apply response', response);
if (!response) {
console.log('apply no response data', data);
dispatch({
type: GET_SYNC_COMPLETED,
data
@ -920,6 +928,7 @@ function doGetSync(passedPassword, callback) {
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
console.log('setSync');
dispatch(doSetSync(data.syncHash, walletHash, walletData));
}

80
dist/bundle.js vendored
View file

@ -630,6 +630,10 @@ Lbryio.authenticate = function () {
Lbryio.getAuthToken().then(function (token) {
if (!token || token.length > 60) {
return false;
}
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(token);
} // check that token works
@ -644,46 +648,47 @@ Lbryio.authenticate = function () {
}
return lbry_redux__WEBPACK_IMPORTED_MODULE_1__["Lbry"].status().then(function (status) {
if (Lbryio.overrides.setAuthToken) {
return Lbryio.overrides.setAuthToken(status);
} // simply call the logic to create a new user, and obtain the auth token
return (// simply call the logic to create a new user, and obtain the auth token
new Promise(function (res, rej) {
Lbryio.call('user', 'new', {
auth_token: '',
language: 'en',
app_id: status.installation_id
}, 'post').then(function (response) {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
var _window2 = window,
store = _window2.store;
return new Promise(function (res, rej) {
Lbryio.call('user', 'new', {
auth_token: '',
language: 'en',
app_id: status.installation_id
}, 'post').then(function (response) {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(response.auth_token);
}
var _window2 = window,
store = _window2.store;
if (store) {
store.dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GENERATE_AUTH_TOKEN_SUCCESS"],
data: {
authToken: response.auth_token
}
});
}
if (store) {
store.dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GENERATE_AUTH_TOKEN_SUCCESS"],
data: {
authToken: response.auth_token
}
});
}
Lbryio.authToken = response.auth_token;
return res(response);
})["catch"](function (error) {
return rej(error);
});
})
);
}).then(function (newUser) {
if (!newUser) {
return Lbryio.getCurrentUser();
}
Lbryio.authToken = response.auth_token;
res(response);
})["catch"](function (error) {
return rej(error);
});
});
return newUser;
});
}).then(function (user) {
if (!user) {
return Lbryio.getCurrentUser();
}
return user;
}).then(resolve, reject);
});
}
@ -3563,6 +3568,7 @@ function doSetDefaultAccount(success, failure) {
};
}
function doSetSync(oldHash, newHash, data) {
console.log('doSetSync newhash, data', newHash, data);
return function (dispatch) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SYNC_STARTED"]
@ -3601,6 +3607,7 @@ function doGetSync(passedPassword, callback) {
throw new Error('Second argument passed to "doGetSync" must be a function');
}
console.log('callback hasnewdata', hasNewData);
callback(error, hasNewData);
}
}
@ -3632,6 +3639,7 @@ function doGetSync(passedPassword, callback) {
}, 'post');
}).then(function (response) {
var syncHash = response.hash;
console.log('hash response', response);
data.syncHash = syncHash;
data.syncData = response.data;
data.changed = response.changed;
@ -3645,7 +3653,10 @@ function doGetSync(passedPassword, callback) {
});
}
}).then(function (response) {
console.log('apply response', response);
if (!response) {
console.log('apply no response data', data);
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GET_SYNC_COMPLETED"],
data: data
@ -3659,6 +3670,7 @@ function doGetSync(passedPassword, callback) {
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
console.log('setSync');
dispatch(doSetSync(data.syncHash, walletHash, walletData));
}

View file

@ -125,6 +125,9 @@ Lbryio.authenticate = () => {
if (!token || token.length > 60) {
return false;
}
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(token);
}
// check that token works
return Lbryio.getCurrentUser()
@ -136,49 +139,49 @@ Lbryio.authenticate = () => {
return user;
}
return Lbry.status().then(status => {
if (Lbryio.overrides.setAuthToken) {
return Lbryio.overrides.setAuthToken(status);
}
return Lbry.status()
.then(
status =>
// simply call the logic to create a new user, and obtain the auth token
new Promise((res, rej) => {
Lbryio.call(
'user',
'new',
{
auth_token: '',
language: 'en',
app_id: status.installation_id,
},
'post'
)
.then(response => {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
// simply call the logic to create a new user, and obtain the auth token
return new Promise((res, rej) => {
Lbryio.call(
'user',
'new',
{
auth_token: '',
language: 'en',
app_id: status.installation_id,
},
'post'
)
.then(response => {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
const { store } = window;
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(response.auth_token);
}
const { store } = window;
if (store) {
store.dispatch({
type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS,
data: { authToken: response.auth_token },
});
}
Lbryio.authToken = response.auth_token;
res(response);
if (store) {
store.dispatch({
type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS,
data: { authToken: response.auth_token },
});
}
Lbryio.authToken = response.auth_token;
return res(response);
})
.catch(error => rej(error));
})
.catch(error => rej(error));
)
.then(newUser => {
if (!newUser) {
return Lbryio.getCurrentUser();
}
return newUser;
});
});
})
.then(user => {
if (!user) {
return Lbryio.getCurrentUser();
}
return user;
})
.then(resolve, reject);
});

View file

@ -52,6 +52,7 @@ export function doSetDefaultAccount(success, failure) {
}
export function doSetSync(oldHash, newHash, data) {
console.log('doSetSync newhash, data', newHash, data);
return dispatch => {
dispatch({
type: ACTIONS.SET_SYNC_STARTED,
@ -86,6 +87,7 @@ export function doGetSync(passedPassword, callback) {
throw new Error('Second argument passed to "doGetSync" must be a function');
}
console.log('callback hasnewdata', hasNewData);
callback(error, hasNewData);
}
}
@ -116,6 +118,7 @@ export function doGetSync(passedPassword, callback) {
.then(hash => Lbryio.call('sync', 'get', { hash }, 'post'))
.then(response => {
const syncHash = response.hash;
console.log('hash response', response);
data.syncHash = syncHash;
data.syncData = response.data;
data.changed = response.changed;
@ -126,7 +129,9 @@ export function doGetSync(passedPassword, callback) {
}
})
.then(response => {
console.log('apply response', response);
if (!response) {
console.log('apply no response data', data);
dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data });
handleCallback(null, data.changed);
return;
@ -136,6 +141,7 @@ export function doGetSync(passedPassword, callback) {
if (walletHash !== data.syncHash) {
// different local hash, need to synchronise
console.log('setSync');
dispatch(doSetSync(data.syncHash, walletHash, walletData));
}