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 => { 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,46 +335,44 @@ 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); Lbryio.call('user', 'new', {
} // simply call the logic to create a new user, and obtain the auth token 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) => { if (Lbryio.overrides.setAuthToken) {
Lbryio.call('user', 'new', { Lbryio.overrides.setAuthToken(response.auth_token);
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 { if (store) {
store store.dispatch({
} = window; type: GENERATE_AUTH_TOKEN_SUCCESS,
data: {
authToken: response.auth_token
}
});
}
if (store) { Lbryio.authToken = response.auth_token;
store.dispatch({ return res(response);
type: GENERATE_AUTH_TOKEN_SUCCESS, }).catch(error => rej(error));
data: { })).then(newUser => {
authToken: response.auth_token if (!newUser) {
} return Lbryio.getCurrentUser();
}); }
}
Lbryio.authToken = response.auth_token; return newUser;
res(response);
}).catch(error => rej(error));
});
}); });
}).then(user => {
if (!user) {
return Lbryio.getCurrentUser();
}
return user;
}).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));
} }

80
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,46 +648,47 @@ 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 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) { if (Lbryio.overrides.setAuthToken) {
Lbryio.call('user', 'new', { Lbryio.overrides.setAuthToken(response.auth_token);
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, if (store) {
store = _window2.store; store.dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GENERATE_AUTH_TOKEN_SUCCESS"],
data: {
authToken: response.auth_token
}
});
}
if (store) { Lbryio.authToken = response.auth_token;
store.dispatch({ return res(response);
type: constants_action_types__WEBPACK_IMPORTED_MODULE_0__["GENERATE_AUTH_TOKEN_SUCCESS"], })["catch"](function (error) {
data: { return rej(error);
authToken: response.auth_token });
} })
}); );
} }).then(function (newUser) {
if (!newUser) {
return Lbryio.getCurrentUser();
}
Lbryio.authToken = response.auth_token; return newUser;
res(response);
})["catch"](function (error) {
return rej(error);
});
});
}); });
}).then(function (user) {
if (!user) {
return Lbryio.getCurrentUser();
}
return user;
}).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,49 +139,49 @@ 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
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 const { store } = window;
return new Promise((res, rej) => { if (Lbryio.overrides.setAuthToken) {
Lbryio.call( Lbryio.overrides.setAuthToken(response.auth_token);
'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 (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;
return res(response);
Lbryio.authToken = response.auth_token; })
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); .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));
} }