mardi 19 janvier 2016

(beginner) Ember Simple Auth : cookie storage not working properly

I'm currently using Ember Simple Auth with oAuth2 to run a session on my app, and I have a problem : basically we're using the classic Adaptive Store to store our session, but we need to implement an option to keep (or not) the session after restarting the browser.

After a long search the lone idea I had was using a cookie. So, I did something like this in the login controller :

this.validate().then(function isValid(){
        // get the properties sent from the form and if there is any attemptedTransition set
        const keepLoggedIn  =  _this.get('keepLoggedIn');

        if (keepLoggedIn){
          _this.set('session.store', AdaptiveStore.create());
        }else{
          _this.set('session.store', CookieStore.create());
          _this.set('session.store.cookieExpirationTime', null);
        }

        // rest of the code here...
}

The problem is : if I check it works properly, it's using adaptive and I can refresh, it's ok. If I don't, it will instantiate the cookie, it will correctly log in and redirect to the backend, but then if I refresh the browser, I LOSE THE SESSION and need to reconnect.

I checked the detail and the cookie is still here, but not recognized by the router that throws the authenticatedMixin...

Do you have an idea how to make it work properly ?

Thanks a lot.




Aucun commentaire:

Enregistrer un commentaire