From 8f1084e0c09fb168afed1740e1f1aaa21ec61ee6 Mon Sep 17 00:00:00 2001 From: bobrimperator Date: Thu, 2 Jan 2025 03:33:01 +0100 Subject: [PATCH] fix(ember-simple-auth): setting non 'content' fields with #set on ObjectProxy is not reactive. --- packages/ember-simple-auth/src/services/session.ts | 14 ++++---------- packages/test-app/app/controllers/application.js | 1 + packages/test-app/app/templates/application.hbs | 7 ++++++- .../tests/acceptance/authentication-test.js | 6 ++++++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/ember-simple-auth/src/services/session.ts b/packages/ember-simple-auth/src/services/session.ts index c90ae1ec6..0d35add42 100644 --- a/packages/ember-simple-auth/src/services/session.ts +++ b/packages/ember-simple-auth/src/services/session.ts @@ -11,7 +11,7 @@ import { handleSessionInvalidated, } from '../-internals/routing'; import type Transition from '@ember/routing/transition'; -import { alias } from '@ember/object/computed'; +import { alias, readOnly } from '@ember/object/computed'; const SESSION_DATA_KEY_PREFIX = /^data\./; @@ -90,9 +90,7 @@ export default class SessionService extends Service { @default false @public */ - get isAuthenticated() { - return this.session.isAuthenticated; - } + @readOnly('session.isAuthenticated') declare isAuthenticated: boolean; /** The current session data as a plain object. The @@ -109,9 +107,7 @@ export default class SessionService extends Service { @default { authenticated: {} } @public */ - get data() { - return this.session.content; - } + @readOnly('session.content') declare data: Data; /** The session store. @@ -123,9 +119,7 @@ export default class SessionService extends Service { @default null @public */ - get store() { - return this.session.store; - } + @readOnly('session.store') declare store: unknown; /** A previously attempted but intercepted transition (e.g. by the diff --git a/packages/test-app/app/controllers/application.js b/packages/test-app/app/controllers/application.js index f19fc8c40..24a11a9df 100644 --- a/packages/test-app/app/controllers/application.js +++ b/packages/test-app/app/controllers/application.js @@ -4,6 +4,7 @@ import { action } from '@ember/object'; export default class ApplicationController extends Controller { @service router; + @service session; @action transitionToLoginRoute() { diff --git a/packages/test-app/app/templates/application.hbs b/packages/test-app/app/templates/application.hbs index dce83c9e0..e4ad11212 100644 --- a/packages/test-app/app/templates/application.hbs +++ b/packages/test-app/app/templates/application.hbs @@ -1,4 +1,9 @@ -
+
{{outlet}} +
+ + \ No newline at end of file diff --git a/packages/test-app/tests/acceptance/authentication-test.js b/packages/test-app/tests/acceptance/authentication-test.js index 068d753e7..2efafa11a 100644 --- a/packages/test-app/tests/acceptance/authentication-test.js +++ b/packages/test-app/tests/acceptance/authentication-test.js @@ -35,10 +35,16 @@ module('Acceptance: Authentication', function (hooks) { await invalidateSession(); await visit('/login'); + assert + .dom('[data-test-reactivity] [data-is-authenticated]') + .doesNotExist('not authenticated yet.'); await fillIn('[data-test-identification]', 'identification'); await fillIn('[data-test-password]', 'password'); await click('button[type="submit"]'); + assert + .dom('[data-test-reactivity] [data-is-authenticated]') + .exists('session.isAuthenticated is reactive'); assert.equal(currentURL(), '/'); });