Skip to content

Commit

Permalink
Save token to local storage. #119
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielflorit committed Nov 30, 2014
1 parent 1ec090e commit 42021f2
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/js/components/Livecoding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ var updateData = require('../../../.tmp/updates.json');
// Create the React component.
var Livecoding = React.createClass({

// TODO: get/set from local storage
_token: null,
statics: {
TOKEN: 'LIVECODING_TOKEN'
},

getToken: function() {
return localStorage.getItem(Livecoding.TOKEN);
},

setToken: function(token) {
localStorage.setItem(Livecoding.TOKEN, token);
},

// Set the initial state. As the application grows, so
// will the number of state properties.
Expand Down Expand Up @@ -120,7 +129,7 @@ var Livecoding = React.createClass({
case 'file:save':

// Is user logged in? If so, save.
if (this._token) {
if (this.getToken()) {

// Create payload.
var data = _.pick(this.state, [
Expand All @@ -131,7 +140,7 @@ var Livecoding = React.createClass({
]);

// Save to gist.
Authentication.save(this._token, data)
Authentication.save(this.getToken(), data)
.then(function(gist) {

// Do nothing for now.
Expand All @@ -153,7 +162,7 @@ var Livecoding = React.createClass({
handleAuthenticationToken: function(topic, response) {

// Save the token.
this._token = response.token;
this.setToken(response.token);

// Get next step.
var next = this.afterAuthentication.pop();
Expand All @@ -170,7 +179,7 @@ var Livecoding = React.createClass({
]);

// Save to gist.
Authentication.save(this._token, data)
Authentication.save(this.getToken(), data)
.then(function(gist) {

// Do nothing for now.
Expand Down

0 comments on commit 42021f2

Please sign in to comment.