diff --git a/packages/ember-simple-auth/addon/services/session.js b/packages/ember-simple-auth/addon/services/session.js index a4dea4eeb..665a0ea38 100644 --- a/packages/ember-simple-auth/addon/services/session.js +++ b/packages/ember-simple-auth/addon/services/session.js @@ -1,9 +1,7 @@ import { alias, readOnly } from '@ember/object/computed'; -import { A } from '@ember/array'; import Service from '@ember/service'; -import Evented from '@ember/object/evented'; import { getOwner } from '@ember/application'; -import { assert, deprecate } from '@ember/debug'; +import { assert } from '@ember/debug'; import Configuration from '../configuration'; import { @@ -16,20 +14,6 @@ import { const SESSION_DATA_KEY_PREFIX = /^data\./; -let enableEventsDeprecation = true; -function deprecateSessionEvents() { - if (enableEventsDeprecation) { - deprecate("Ember Simple Auth: The session service's events API is deprecated; to add custom behavior to the authentication or invalidation handling, override the handleAuthentication or handleInvalidation methods.", false, { - id: 'ember-simple-auth.events.session-service', - until: '4.0.0', - for: 'ember-simple-auth', - since: { - enabled: '3.1.0' - } - }); - } -} - function assertSetupHasBeenCalled(isSetupCalled) { if (!isSetupCalled) { assert("Ember Simple Auth: session#setup wasn't called. Make sure to call session#setup in your application route's beforeModel hook.", false); @@ -54,10 +38,9 @@ function assertSetupHasBeenCalled(isSetupCalled) { @class SessionService @module ember-simple-auth/services/session @extends Ember.Service - @uses Ember.Evented @public */ -export default Service.extend(Evented, { +export default Service.extend({ /** Triggered whenever the session is successfully authenticated. This happens when the session gets authenticated via @@ -140,7 +123,6 @@ export default Service.extend(Evented, { init() { this._super(...arguments); this.set('session', getOwner(this).lookup('session:main')); - this._forwardSessionEvents(); }, set(key, value) { @@ -153,53 +135,6 @@ export default Service.extend(Evented, { } }, - _forwardSessionEvents() { - A([ - 'authenticationSucceeded', - 'invalidationSucceeded' - ]).forEach((event) => { - const session = this.get('session'); - // the internal session won't be available in route unit tests - if (session) { - session.on(event, () => { - enableEventsDeprecation = false; - this.trigger(event, ...arguments); - enableEventsDeprecation = true; - }); - } - }); - }, - - on() { - deprecateSessionEvents(); - - return this._super(...arguments); - }, - - one() { - deprecateSessionEvents(); - - return this._super(...arguments); - }, - - off() { - deprecateSessionEvents(); - - return this._super(...arguments); - }, - - has() { - deprecateSessionEvents(); - - return this._super(...arguments); - }, - - trigger() { - deprecateSessionEvents(); - - return this._super(...arguments); - }, - _setupHandlers() { this.get('session').on('authenticationSucceeded', () => this.handleAuthentication(Configuration.routeAfterAuthentication)); this.get('session').on('invalidationSucceeded', () => this.handleInvalidation(Configuration.rootURL)); diff --git a/packages/ember-simple-auth/tests/unit/services/session-test.js b/packages/ember-simple-auth/tests/unit/services/session-test.js index c3da8e1cd..3b700d731 100644 --- a/packages/ember-simple-auth/tests/unit/services/session-test.js +++ b/packages/ember-simple-auth/tests/unit/services/session-test.js @@ -31,72 +31,6 @@ module('SessionService', function(hooks) { sinon.restore(); }); - test('forwards the "authenticationSucceeded" event from the session', async function(assert) { - assert.expect(2); - let deprecations = []; - registerDeprecationHandler((message, options, next) => { - deprecations.push(message); - - next(message, options); - }); - let triggered = false; - sinon.stub(sessionService, 'handleAuthentication'); - sessionService.one('authenticationSucceeded', () => (triggered = true)); - session.trigger('authenticationSucceeded'); - - await new Promise(resolve => { - next(() => { - assert.ok(triggered); - assert.equal(deprecations.filter(deprecation => deprecation.includes('Ember Simple Auth:')).length, 1); // the call to .one above triggers a deprecation but forwarding the event should *not* trigger a deprecation - resolve(); - }); - }); - }); - - test('forwards the "invalidationSucceeded" event from the session', async function(assert) { - assert.expect(2); - let deprecations = []; - registerDeprecationHandler((message, options, next) => { - deprecations.push(message); - - next(message, options); - }); - let triggered = false; - sessionService.one('invalidationSucceeded', () => (triggered = true)); - session.trigger('invalidationSucceeded'); - - await new Promise(resolve => { - next(() => { - assert.ok(triggered); - assert.equal(deprecations.filter(deprecation => deprecation.includes('Ember Simple Auth:')).length, 1); // the call to .one above triggers a deprecation but forwarding the event should *not* trigger a deprecation - resolve(); - }); - }); - }); - - test('deprecates using the "Evented" API', function(assert) { - assert.expect(6); - let deprecations = []; - registerDeprecationHandler((message, options, next) => { - deprecations.push(message); - - next(message, options); - }); - - let handler = () => {}; - sessionService.trigger('invalidationSucceeded'); - sessionService.on('invalidationSucceeded', handler); - sessionService.off('invalidationSucceeded', handler); - sessionService.has('invalidationSucceeded'); - sessionService.one('invalidationSucceeded', handler); - - let emberSimpleAuthDeprecations = deprecations.filter(deprecation => deprecation.includes('Ember Simple Auth:')); - assert.equal(emberSimpleAuthDeprecations.length, 5); - for (let deprecation of emberSimpleAuthDeprecations) { - assert.equal(deprecation, "Ember Simple Auth: The session service's events API is deprecated; to add custom behavior to the authentication or invalidation handling, override the handleAuthentication or handleInvalidation methods."); - } - }); - module('isAuthenticated', function() { test('is read from the session', function(assert) { session.set('isAuthenticated', true);