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

35
dist/bundle.es.js vendored
View file

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

36
dist/bundle.js vendored
View file

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

View file

@ -125,6 +125,9 @@ Lbryio.authenticate = () => {
if (!token || token.length > 60) { if (!token || token.length > 60) {
return false; return false;
} }
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(token);
}
// check that token works // check that token works
return Lbryio.getCurrentUser() return Lbryio.getCurrentUser()
@ -136,13 +139,11 @@ Lbryio.authenticate = () => {
return user; return user;
} }
return Lbry.status().then(status => { return Lbry.status()
if (Lbryio.overrides.setAuthToken) { .then(
return Lbryio.overrides.setAuthToken(status); status =>
}
// simply call the logic to create a new user, and obtain the auth token // simply call the logic to create a new user, and obtain the auth token
return new Promise((res, rej) => { new Promise((res, rej) => {
Lbryio.call( Lbryio.call(
'user', 'user',
'new', 'new',
@ -159,26 +160,28 @@ Lbryio.authenticate = () => {
} }
const { store } = window; const { store } = window;
if (Lbryio.overrides.setAuthToken) {
Lbryio.overrides.setAuthToken(response.auth_token);
}
if (store) { if (store) {
store.dispatch({ store.dispatch({
type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS, type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS,
data: { authToken: response.auth_token }, data: { authToken: response.auth_token },
}); });
} }
Lbryio.authToken = response.auth_token; Lbryio.authToken = response.auth_token;
res(response); return res(response);
}) })
.catch(error => rej(error)); .catch(error => rej(error));
});
});
}) })
.then(user => { )
if (!user) { .then(newUser => {
if (!newUser) {
return Lbryio.getCurrentUser(); return Lbryio.getCurrentUser();
} }
return newUser;
return user; });
}) })
.then(resolve, reject); .then(resolve, reject);
}); });

View file

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