Skip to content

Commit

Permalink
fix(ember-simple-auth): session must alias attemptedTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
BobrImperator committed Dec 26, 2024
1 parent d448cc9 commit 3e719a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/ember-simple-auth/babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand Down
22 changes: 10 additions & 12 deletions packages/ember-simple-auth/src/services/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\./;

Expand All @@ -36,6 +37,7 @@ type InternalSessionMock = {
requireAuthentication: (transition: Transition, routeOrCallback: RouteOrCallback) => boolean;
prohibitAuthentication: (routeOrCallback: RouteOrCallback) => boolean;
restore: () => Promise<void>;
set(key: string, value: any): void;
};

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
30 changes: 0 additions & 30 deletions packages/test-esa/tests/unit/services/session-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3e719a5

Please sign in to comment.