Skip to content

services/session: Clear in-memory data when logging out #5180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ export default class SessionService extends Service {
logoutTask = task(async () => {
await ajax(`/api/private/session`, { method: 'DELETE' });

this.savedTransition = null;
this.isLoggedIn = false;

await this.loadUserTask.cancelAll({ resetState: true });
this.sentry.setUser(null);

this.router.transitionTo('index');
// We perform a proper page navigation here instead of an in-app transition to ensure
// that the Ember Data store and any other in-memory data is cleared on logout.
window.location.assign('/');
});

loadUserTask = dropTask(async () => {
Expand Down
7 changes: 5 additions & 2 deletions tests/acceptance/logout-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { click, currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';

import window from 'ember-window-mock';
import { setupWindowMock } from 'ember-window-mock/test-support';

import { setupApplicationTest } from 'cargo/tests/helpers';

module('Acceptance | Logout', function (hooks) {
setupApplicationTest(hooks);
setupWindowMock(hooks);

test('successful logout', async function (assert) {
let user = this.server.create('user', { name: 'John Doe' });
Expand All @@ -17,7 +21,6 @@ module('Acceptance | Logout', function (hooks) {
await click('[data-test-user-menu] [data-test-toggle]');
await click('[data-test-user-menu] [data-test-logout-button]');

assert.equal(currentURL(), '/');
assert.dom('[data-test-user-menu] [data-test-toggle]').doesNotExist();
assert.equal(window.location.pathname, '/');
});
});