Merge pull request #103 from lbryio/doAuth-changes

doAuth changes
This commit is contained in:
Sean Yesmunt 2020-09-09 10:39:38 -04:00 committed by GitHub
commit 9440717a00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 85 deletions

65
dist/bundle.es.js vendored
View file

@ -343,46 +343,43 @@ Lbryio.authenticate = () => {
return user; return user;
} }
return lbryRedux.Lbry.status().then(status => { return lbryRedux.Lbry.status().then(status => new Promise((res, rej) => {
if (Lbryio.overrides.setAuthToken) { Lbryio.call('user', 'new', {
return Lbryio.overrides.setAuthToken(status); auth_token: '',
} // simply call the logic to create a new user, and obtain the 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);
}); });
} }

23
dist/bundle.js vendored
View file

@ -656,11 +656,6 @@ 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 Lbryio.overrides.setAuthToken(status);
} // simply call the logic to create a new user, and obtain the auth token
return new Promise(function (res, rej) { return new Promise(function (res, rej) {
Lbryio.call('user', 'new', { Lbryio.call('user', 'new', {
auth_token: '', auth_token: '',
@ -674,6 +669,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"],
@ -684,18 +683,18 @@ 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 (newUser) {
}).then(function (user) { if (!newUser) {
if (!user) { return Lbryio.getCurrentUser();
return Lbryio.getCurrentUser(); }
}
return user; return newUser;
});
}).then(resolve, reject); }).then(resolve, reject);
}); });
} }

View file

@ -136,49 +136,48 @@ 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 =>
} 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);
}); });