ember-simple-auth user stays logged in despite browser relaunch

118 views Asked by At

For some reason my user is still logged in despite closing my Safari browser.

These are the versions of Ember & stuff that I'm using:

ember-cli: 3.25.3
node: 14.16.0
os: darwin x64

This is my authentication code:

this.session.authenticate('authenticator:devise', this.fields.email, this.fields.password)

And this is my app/services/session.js file:

import { inject as service } from '@ember/service';
import BaseSessionService from 'ember-simple-auth/services/session';

export default class SessionService extends BaseSessionService {
  @service currentUser;

  async handleAuthentication(routeAfterAuthentication) {
    try {
      await this.currentUser.load();
      super.handleAuthentication(...arguments);
    } catch(err) {
      await this.invalidate();
    }
  }
}

and I'm checking my logged in status via:

this.session.isAuthenticated

It says here https://ember-simple-auth.com/api/classes/CookieStore.html that:

By default the cookie session store uses a session cookie that expires and is deleted when the browser is closed.

So how come my user is still authenticated despite closing my browser - any ideas or suggestions?

1

There are 1 answers

0
jrjohnson On

The cookie store isn't the default store. You'll need to configure this like:

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

export default class ApplicationSessionStore extends Cookie {}

according to the documentation in the README.