2018-10-05 21:46:33 +03:00
|
|
|
import EphemeralStore from 'ember-simple-auth/session-stores/ephemeral';
|
|
|
|
import RSVP from 'rsvp';
|
|
|
|
import {inject as service} from '@ember/service';
|
2016-01-12 18:38:38 +03:00
|
|
|
|
2018-10-05 21:46:33 +03:00
|
|
|
// Ghost already uses a cookie to store it's session so we don't need to keep
|
|
|
|
// track of any other peristent login state separately in Ember Simple Auth
|
2022-02-02 21:41:16 +03:00
|
|
|
export default class ApplicationStore extends EphemeralStore {
|
|
|
|
@service session;
|
2015-10-18 21:17:02 +03:00
|
|
|
|
2018-10-05 21:46:33 +03:00
|
|
|
// when loading the app we want ESA to try fetching the currently logged
|
|
|
|
// in user. This will succeed/fail depending on whether we have a valid
|
|
|
|
// session cookie or not so we can use that as an indication of the session
|
|
|
|
// being authenticated
|
|
|
|
restore() {
|
2021-07-08 16:37:31 +03:00
|
|
|
return this.session.populateUser().then(() => {
|
2018-10-05 21:46:33 +03:00
|
|
|
// provide the necessary data for internal-session to mark the
|
|
|
|
// session as authenticated
|
|
|
|
let data = {authenticated: {authenticator: 'authenticator:cookie'}};
|
|
|
|
this.persist(data);
|
|
|
|
return data;
|
|
|
|
}).catch(() => {
|
|
|
|
return RSVP.reject();
|
|
|
|
});
|
|
|
|
}
|
2022-02-02 21:41:16 +03:00
|
|
|
}
|