mardi 9 mai 2017

Data returned during ember simple auth authentication

My app has a login page which authenticates a user and grants them access to the rest of the app.

import Ember from 'ember';

export default Ember.Controller.extend({
    session: Ember.inject.service('session'),
    actions: {
        authenticate(){
            let{identification, password} = this.getProperties('identification', 'password');

            var _this = this;

            this.get('session').authenticate('authenticator:oauth2', identification, password).then(()=> {
                alert(this.get('session.data')); //This doesn't show the serial that I return
                _this.transitionToRoute('home');
            }, (err)=> {
                _this.set('errorMessage', err.error);
            });
        }
    }
});

I am authenticating the session using oauth2 and then transitioning to my home page. I need some data (a serial number) to be returned during authentication and stored in my session. This serial is then needed for my home route to fetch the correct model. The problem that I am having is that the serial that I am returning is not being stored in session.data.

I am using express on my backend to handle the authentication post request. When everything is successful my express server responds back with

res.status(200).send({token: "random token", serial: "serial number"});

In my code above, when I call alert(this.get('session.data')); it will show the token that the server responded with but NOT the serial. Why is the serial not also being stored in the session data?




Aucun commentaire:

Enregistrer un commentaire