beforeEach(() => { store = Adaptive.extend({ _createStore(storeType, options) { return this._super(storeType, assign(options, { _isFastBoot: false })); } }).create({ _isLocalStorageAvailable: true }); });
beforeEach(() => { cookieService = FakeCookieService.create(); sinon.spy(cookieService, 'read'); sinon.spy(cookieService, 'write'); store = Adaptive.extend({ _createStore(storeType, options) { return this._super(storeType, assign({}, options, { _isFastBoot: false })); } }).create({ _isLocalStorageAvailable: false, _cookies: cookieService }); });
export default function createAdaptiveStore( cookiesService, options = {}, props = {} ) { let cookieStore = createCookieStore( cookiesService, assign({}, options, { _isFastboot: false }) ); props._createStore = function() { cookieStore.on('sessionDataUpdated', data => { this.trigger('sessionDataUpdated', data); }); return cookieStore; }; return Adaptive.extend(props).create(options); }
describe('when localStorage is not available', () => { let cookieService; beforeEach(() => { cookieService = FakeCookieService.create(); sinon.spy(cookieService, 'read'); sinon.spy(cookieService, 'write'); store = Adaptive.extend({ _createStore(storeType, options) { return this._super(storeType, assign({}, options, { _isFastBoot: false })); } }).create({ _isLocalStorageAvailable: false, _cookies: cookieService }); }); itBehavesLikeAStore({ store() { return store; } }); itBehavesLikeACookieStore({ createStore(cookieService, options = {}) { options._isLocalStorageAvailable = false; return Adaptive.extend({ _cookies: cookieService, _fastboot: { isFastBoot: false }, _createStore(storeType, options) { return this._super(storeType, assign({}, options, { _isFastBoot: false })); } }).create(options); }, renew(store, data) { return store.get('_store')._renew(data); }, sync(store) { store.get('_store')._syncData(); }, spyRewriteCookieMethod(store) { sinon.spy(store.get('_store'), 'rewriteCookie'); return store.get('_store').rewriteCookie; } }); it('persists to cookie when cookie attributes change', () => { let now = new Date(); run(() => { store.persist({ key: 'value' }); store.setProperties({ cookieName: 'test:session', cookieExpirationTime: 60 }); }); expect(cookieService.write).to.have.been.calledWith( 'test:session-expiration_time', 60, sinon.match(function({ domain, expires, path, secure }) { return domain === null && path === '/' && secure === false && expires >= new Date(now.getTime() + 60 * 1000); }) ); }); });
//import Ember from 'ember'; import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive'; export default AdaptiveStore.extend();
import Ember from 'ember'; import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive'; const { $ } = Ember; export default AdaptiveStore.extend({ cookieName: 'XSRF-TOKEN' }); $(function() { var token = $('meta[name="csrf-token"]').attr('content'); return $.ajaxPrefilter(function(options, originalOptions, xhr) { return xhr.setRequestHeader('X-CSRF-Token', token); }); });
import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive'; import ghostPaths from 'ghost/utils/ghost-paths'; const paths = ghostPaths(); const keyName = `ghost${(paths.subdir.indexOf('/') === 0 ? `-${paths.subdir.substr(1)}` : ``) }:session`; export default AdaptiveStore.extend({ localStorageKey: keyName, cookieName: keyName });
import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive'; export default AdaptiveStore.extend({ localStorageKey: 'ghost:session', cookieName: 'ghost:session' });