Ember simple auth session content lost after page reload

686 Views Asked by At

I've created a clean ember app, installed simple-auth and implemented a custom authenticator for facebook.

https://github.com/prule/ember-auth-spike

I can see that I'm successfully getting the access token from FB and its put in the session (inspecting the container session via chrome ember extension shows me the session is authenticated and the access token is visible).

But when I reload the page in the browser, the session state is lost. Is this expected behaviour? Have I done something wrong in my custom authenticator? The authenticator code is a straight copy and paste (plus some console.logs) from https://github.com/simplabs/ember-simple-auth/blob/master/examples/7-multiple-external-providers.html

Thanks, I appreciate any help.

import Ember from 'ember';
import Base from 'simple-auth/authenticators/base';

export default Base.extend({
  restore: function (data) {
    return new Ember.RSVP.Promise(function (resolve, reject) {
      console.log('restore');
      if (!Ember.isEmpty(properties.accessToken)) {
        console.log('found access token '+properties.accessToken);
        resolve(properties);
      }
      else {
        console.log('no token found');
        reject();
      }
    });
  },
  authenticate: function (options) {
    return new Ember.RSVP.Promise(function (resolve, reject) {
      console.log('1');
      FB.getLoginStatus(function (fbResponse) {
        console.log('2');
        console.log(fbResponse);

        if (fbResponse.status === 'connected') {
          Ember.run(function () {
            console.log(fbResponse.authResponse.accessToken);

            resolve({accessToken: fbResponse.authResponse.accessToken});
          });
        }
        else if (fbResponse.status === 'not_authorized') {
          reject();
        }
        else {
          FB.login(function (fbResponse) {
            if (fbResponse.authResponse) {
              Ember.run(function () {
                console.log(fbResponse.authResponse.accessToken);

                resolve({accessToken: fbResponse.authResponse.accessToken});
              });
            }
            else {
              reject();
            }
          });
        }
      });
    });
  },
  invalidate: function (data) {
    return new Ember.RSVP.Promise(function (resolve, reject) {
      FB.logout(function (response) {
        Ember.run(resolve);
      });
    });
  }
});
1

There are 1 best solutions below

1
On BEST ANSWER

The argument to the authenticator's restore method is called data but you're checking for properties.accessToken. This should actually raise an error anyway as properties is undefined there.