diff --git a/ui/core/app/routes/application.js b/ui/core/app/routes/application.js index e67f524e1..0874bb7f0 100644 --- a/ui/core/app/routes/application.js +++ b/ui/core/app/routes/application.js @@ -59,4 +59,15 @@ export default class ApplicationRoute extends Route.extend( invalidateSession() { this.session.invalidate(); } + + @action + error(e) { + const isUnauthenticated = e?.errors[0]?.isUnauthenticated; + if (isUnauthenticated) { + this.session.invalidate(); + return false; + } else { + return true; + } + } } diff --git a/ui/core/tests/acceptance/authentication-test.js b/ui/core/tests/acceptance/authentication-test.js index fa43f2247..f7abb618b 100644 --- a/ui/core/tests/acceptance/authentication-test.js +++ b/ui/core/tests/acceptance/authentication-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import { visit, currentURL, fillIn, click, find, findAll } from '@ember/test-helpers'; +import { visit, currentURL, fillIn, click, find, findAll, setupOnerror } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import { Response } from 'miragejs'; @@ -180,4 +180,16 @@ module('Acceptance | authentication', function (hooks) { assert.notOk(currentSession().isAuthenticated); assert.equal(currentURL(), authMethodGlobalAuthenticateURL); }); + + test('401 responses result in deauthentication', async function (assert) { + assert.expect(2); + authenticateSession({ scope: { id: globalScope.id, type: globalScope.type } }); + await visit(orgsURL); + assert.ok(currentSession().isAuthenticated, 'Session begins authenticated, before encountering 401'); + this.server.get('/scopes', () => new Response(401)); + setupOnerror(() => { + assert.notOk(currentSession().isAuthenticated, 'Session is unauthenticated, after encountering 401'); + }); + await visit(projectsURL); + }); });