<commit_before>import Ember from 'ember';

export default Ember.Controller.extend({
  currentUser: null,
  logginError: false,
  isAuthenticated: function() {
    this.get('session').isNotExpired();
  }.property('session'),

  savedTransition: function(handleTransition) {
    // make handleTransition the default
    if (typeof handleTransition === 'undefined') {
      handleTransition = true;
    }

    if (handleTransition) {
      var previousTransition = this.get('previousTransition');
      if (previousTransition) {
        this.set('previousTransition', null);
        previousTransition.retry();
      } else {
        this.transitionToRoute('index');
      } 
    }
  },

  loadUser: function(handleTransition) {
    var self = this;
    var adapter = this.get('container').lookup('adapter:session');
    return new Ember.RSVP.Promise(function(resolve, reject) {
      adapter.currentUser().then(function(json) {
        self.store.pushPayload(window.EmberENV['ember-oauth2']['model'], json);

        var modelKey = null;
        for (var key in json) {
          // key could be returned as plural if using JsonApi format.
          if (window.EmberENV['ember-oauth2']['model'] === Ember.String.singularize(key)) {
            modelKey = key;
          }
        }

        var user = self.store.findById(window.EmberENV['ember-oauth2']['model'], json[modelKey]['id']).then(function(user) {
          self.set('logginError', false);
          self.set('currentUser', user);
        });

        self.savedTransition(handleTransition);

        resolve(user);
      }, function(err) {
        self.set('logginError', true);
        reject(err);
      });
    });
  }

});<commit_msg>if the model name key return is pluralized then parse the first user in the array<commit_after>import Ember from 'ember';

export default Ember.Controller.extend({
  currentUser: null,
  logginError: false,
  isAuthenticated: function() {
    this.get('session').isNotExpired();
  }.property('session'),

  savedTransition: function(handleTransition) {
    // make handleTransition the default
    if (typeof handleTransition === 'undefined') {
      handleTransition = true;
    }

    if (handleTransition) {
      var previousTransition = this.get('previousTransition');
      if (previousTransition) {
        this.set('previousTransition', null);
        previousTransition.retry();
      } else {
        this.transitionToRoute('index');
      } 
    }
  },

  loadUser: function(handleTransition) {
    var self = this;
    var adapter = this.get('container').lookup('adapter:session');
    return new Ember.RSVP.Promise(function(resolve, reject) {
      adapter.currentUser().then(function(json) {
        var modelKey = null;
        var modelName = window.EmberENV['ember-oauth2']['model'];
        for (var key in json) {
          // key could be returned as plural if using JsonApi format.
          if (modelName === Ember.String.singularize(key)) {
            modelKey = key;
          }
        }

        var user;
        var data;

        // if model name is pluralized it should be in an array, used for JSON API
        if (modelKey === Ember.String.pluralize(modelName)) {
          data = Ember.A(json[modelKey]).get('firstObject');
          user = self.store.push(modelName, self.store.normalize(modelName, data));
        } else {
          data = json[modelKey];
          user = self.store.push(modelName, self.store.normalize(modelName, data));
        }

        if (user) {
          self.set('logginError', false);
          self.set('currentUser', user);
        }

        self.savedTransition(handleTransition);

        resolve(user);
      }, function(err) {
        self.set('logginError', true);
        reject(err);
      });
    });
  }

});
{'fraction_non_alphanumeric': 0.13435599047870933, 'fraction_numerical': 0.0010579211848717272, 'mean_word_length': 2.629558541266795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3192917', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1049, 'n_words': 231}