<commit_before>import Ember from "ember";

export default Ember.Route.extend({
  model: function(){
    var that   = this;
    var storage = JSON.parse(localStorage.getItem("firebase:session::pairsapp"));
    // var localSession = JSON.parse(localStorage.getItem("localSession"));
    var fb      = new window.Firebase('https://pairsapp.firebaseio.com');
    
    if (!storage) { 
      this.transitionTo('signin'); 
    } else 
    if(!that.session.get('user')) {
      fb.authWithCustomToken(storage.token, function(error, authData) {
        if (error) {
          this.transitionTo('signin'); 
        } else {
          console.log("Authenticated successfully with token:", authData);
          var user = that.get("store").find('user', authData.uid);
          var us   = that.get('store').createRecord('session');
          us.setProperties({
            user:          user,
            uid:           authData.uid,
            provider:      authData.provider,
            auth:          authData.auth,
            expires:       authData.expires,
            email:         authData.email,
            resetPassword: <PASSWORD>
          });
          us.save().then(function () { 
            that.session.set('user', user);
            that.session.set('userSession', us);
            localStorage.setItem("localSession", JSON.stringify(us));
            that.transitionTo("chat");
          });
        }
      });
    }
  }
});
<commit_msg>fixes reload somewhat …<commit_after>import Ember from "ember";

export default Ember.Route.extend({
  model: function(){
    var _this   = this;
    var store  = this.get('store');
    var storage = JSON.parse(localStorage.getItem("firebase:session::pairsapp"));
    var fb      = new window.Firebase('https://pairsapp.firebaseio.com');

    if (!storage) {
      this.transitionTo('signin');
    } else if(!_this.session.get('user')) {
      var promise = new Promise(function(resolve, reject) {
        fb.authWithCustomToken(storage.token, function(error, authData) {
          if (error) {
            _this.transitionTo('signin');
            reject('failed login');
          } else {
            console.log("Authenticated successfully with token:", authData);
            var user = store.find('user', authData.uid);

            user.then(function(user){
              var session   = store.createRecord('session', {
                user:          user,
                uid:           authData.uid,
                provider:      authData.provider,
                auth:          authData.auth,
                expires:       authData.expires,
                resetPassword: <PASSWORD>
              });
              session.save().then(function () {
                _this.session.set('user', user);
                _this.session.set('userSession', session);
                localStorage.setItem("localSession", JSON.stringify(session));
                _this.transitionTo("chat");
                resolve(true);
              });
            });
          }
        });
      });

      return promise;
    }
  }
});

{'fraction_non_alphanumeric': 0.1349335063250081, 'fraction_numerical': 0.0, 'mean_word_length': 1.8293577981651377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2443760', 'n_tokens_mistral': 841, 'n_tokens_neox': 819, 'n_words': 149}