Add auth to lbryio.js

This commit is contained in:
Alex Liebowitz 2017-04-02 05:55:24 -04:00 committed by Jeremy Kauffman
parent 1dbbf8fc01
commit 70d2f7c823
2 changed files with 12 additions and 4 deletions

View file

@ -104,6 +104,7 @@ var App = React.createClass({
app_id: installation_id,
}, 'post').then(({ID}) => {
localStorage.setItem('accessToken', ID);
localStorage.setItem('appId', installation_id);
this.setState({
registrationCheckComplete: true,
justRegistered: true,

View file

@ -80,15 +80,22 @@ lbryio.call = function(resource, action, params, method='get') {
console.log('about to call xhr.open');
// For social media auth:
//const accessToken = localStorage.getItem('accessToken');
//const fullParams = {...params, ... accessToken ? {access_token: accessToken} : {}};
// Temp app ID based auth:
const fullParams = {app_id: localStorage.getItem('appId'), ...params};
if (method == 'get') {
console.info('GET ', CONNECTION_STRING + resource + '/' + action, ' | params:', params);
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(params), true);
console.info('GET ', CONNECTION_STRING + resource + '/' + action, ' | params:', fullParams);
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(fullParams), true);
xhr.send();
} else if (method == 'post') {
console.info('POST ', CONNECTION_STRING + resource + '/' + action, '| params: ', params);
console.info('POST ', CONNECTION_STRING + resource + '/' + action, '| params: ', fullParams);
xhr.open('post', CONNECTION_STRING + resource + '/' + action, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(querystring.stringify(params));
xhr.send(querystring.stringify(fullParams));
}
});
};