From 3e719a5c7e404107f8f1ecf2176d46d8231f7a9a Mon Sep 17 00:00:00 2001 From: bobrimperator Date: Thu, 26 Dec 2024 18:50:38 +0100 Subject: [PATCH] fix(ember-simple-auth): session must alias attemptedTransition --- packages/ember-simple-auth/babel.config.json | 2 +- .../ember-simple-auth/src/services/session.ts | 22 +++++++------- .../tests/unit/services/session-test.js | 30 ------------------- 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/packages/ember-simple-auth/babel.config.json b/packages/ember-simple-auth/babel.config.json index 1f2d1d5279..d3ea846f63 100644 --- a/packages/ember-simple-auth/babel.config.json +++ b/packages/ember-simple-auth/babel.config.json @@ -2,7 +2,7 @@ "plugins": [ [ "@babel/plugin-transform-typescript", - { "allExtensions": true, "onlyRemoveTypeImports": true, "allowDeclareFields": true } + { "allExtensions": true, "onlyRemoveTypeImports": true } ], "@embroider/addon-dev/template-colocation-plugin", ["@babel/plugin-proposal-decorators", { "legacy": true }], diff --git a/packages/ember-simple-auth/src/services/session.ts b/packages/ember-simple-auth/src/services/session.ts index 5bbf20add3..47390e93fc 100644 --- a/packages/ember-simple-auth/src/services/session.ts +++ b/packages/ember-simple-auth/src/services/session.ts @@ -11,6 +11,7 @@ import { handleSessionInvalidated, } from '../-internals/routing'; import type Transition from '@ember/routing/transition'; +import { alias } from '@ember/object/computed'; const SESSION_DATA_KEY_PREFIX = /^data\./; @@ -36,6 +37,7 @@ type InternalSessionMock = { requireAuthentication: (transition: Transition, routeOrCallback: RouteOrCallback) => boolean; prohibitAuthentication: (routeOrCallback: RouteOrCallback) => boolean; restore: () => Promise; + set(key: string, value: any): void; }; /** @@ -58,15 +60,12 @@ type InternalSessionMock = { @public */ export default class EmberSimpleAuthSessionService extends Service { - declare session: InternalSessionMock; + session: InternalSessionMock; - constructor() { - super(...arguments); + constructor(owner: any) { + super(owner); - const owner = getOwner(this); - if (owner) { - this.session = owner.lookup('session:main') as InternalSessionMock; - } + this.session = owner.lookup('session:main') as InternalSessionMock; } /** @@ -132,17 +131,16 @@ export default class EmberSimpleAuthSessionService extends Service { @default null @public */ - get attemptedTransition() { - return this.session.attemptedTransition; - } + @alias('session.attemptedTransition') + attemptedTransition: null | Transition = null; set(key: any, value: any) { const setsSessionData = SESSION_DATA_KEY_PREFIX.test(key); if (setsSessionData) { const sessionDataKey = `session.${key.replace(SESSION_DATA_KEY_PREFIX, '')}`; - return this._super(sessionDataKey, value); + return super.set(sessionDataKey, value); } else { - return this._super(...arguments); + return super.set(key ,value); } } diff --git a/packages/test-esa/tests/unit/services/session-test.js b/packages/test-esa/tests/unit/services/session-test.js index 6946b9541d..fc86b36595 100644 --- a/packages/test-esa/tests/unit/services/session-test.js +++ b/packages/test-esa/tests/unit/services/session-test.js @@ -34,16 +34,6 @@ module('SessionService', function (hooks) { assert.ok(sessionService.get('isAuthenticated')); }); - - test('is read-only', function (assert) { - assert.expect(1); - try { - sessionService.set('isAuthenticated', false); - assert.ok(false); - } catch (e) { - assert.ok(true); - } - }); }); module('store', function () { @@ -52,16 +42,6 @@ module('SessionService', function (hooks) { assert.equal(sessionService.get('store'), 'some store'); }); - - test('is read-only', function (assert) { - assert.expect(1); - try { - sessionService.set('store', 'some other store'); - assert.ok(false); - } catch (e) { - assert.ok(true); - } - }); }); module('attemptedTransition', function () { @@ -96,16 +76,6 @@ module('SessionService', function (hooks) { assert.deepEqual(session.content, { emberSet: 'ember-set-data', authenticated: {} }); }); - - test('is read-only', function (assert) { - assert.expect(1); - try { - sessionService.set('data', false); - assert.ok(false); - } catch (e) { - assert.ok(true); - } - }); }); module('authenticate', function (hooks) {