1

I need to implement a "remember me" feature in my application. I am using the built-in devise authenticator and have the following as my Session Store:

// app/session-stores/application.js
import CookieStore from 'ember-simple-auth/session-stores/cookie';

export default CookieStore.extend({
  cookieName: 'myapp-session-cookie'
});

I have a login-form component with the following:

rememberMe: false,
setExpirationTime() {
  const expirationTime = this.get('rememberMe') ? (14 * 24 * 60 * 60) : null;
  this.set('session.store.cookieExpirationTime', expirationTime);    
},

actions: {
  authenticateWithDevise() {
    this.setExpirationTime();
    let { identification, password } = this.getProperties('identification', 'password');
    this.get('session').authenticate('authenticator:devise', identification, password).then(() => {
      this.sendAction('onLoggedIn');
    }).catch((reason) => {
      this.set('errorMessage', reason.errors[0]);
    });
  }
}

and of course in the corresponding template I have:

<form role="form" {{action "authenticateWithDevise" on="submit"}}>
  {{input type="email" value=identification placeholder="Email" class="icon-email"}}
  {{input type="password" value=password placeholder="Password" class="icon-lock"}}
  {{input id='remember_me' type='checkbox' checked=rememberMe}}
</form>

What happens is session is never remembered, no matter whether cookieExpirationTime was set or null. My question is: should I also implement something else on the server side? I'm currently using devise's rememberable. Also, I've tried searching both here and on github but can only find conversations and code that seems obsolete, like this:

https://github.com/simplabs/ember-simple-auth/pull/451

Can somebody please shed some light? Thanks!

  • I was thinking that the `authenticate` method in Ember Simple Auth's devise authenticator could accept a `rememberMe` param together with `identification` and `password` and send it to the server. In my Rails controller I would include the `Rememberable` module: https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/rememberable.rb and invoke its `remember_me` method if the `rememberMe` param is true. This would be a server-side alternative to `cookieExpirationTime` right? – Davide Papagni May 05 '16 at 05:47

0 Answers0