Skip to content

Instantly share code, notes, and snippets.

@nnance
Last active January 2, 2016 17:09
Show Gist options
  • Save nnance/8335349 to your computer and use it in GitHub Desktop.
Save nnance/8335349 to your computer and use it in GitHub Desktop.
Backbone session management
define([
'underscore',
'backbone',
'backbone.localstorage',
], function (_, Backbone, BBLocalStorage) {
'use strict';
var SessionModel = Backbone.Model.extend({
defaults: {
signedIn: false
},
signin: function(userid, token) {
this.set({
userid: userid,
token: token,
signedIn: true
});
this.save();
},
signout: function() {
this.set('signedIn', false);
this.save();
},
});
var SessionCollection = Backbone.Collection.extend({
model: SessionModel,
localStorage: new Backbone.LocalStorage('eventshero')
});
return { SessionCollection, SessionModel };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment