Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Handle both unauthenticated error messages #2696

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions ui/app/routes/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Transition from '@ember/routing/-private/transition';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';

const ErrInvalidToken = 'invalid authentication token';
const ErrsInvalidToken = ['invalid authentication token', 'Authorization token is not supplied'];

export default class Application extends Route {
@service session!: SessionService;
Expand All @@ -20,8 +20,14 @@ export default class Application extends Route {
@action
error(error: Error): boolean | void {
console.log(error);
let hasAuthError = false;
ErrsInvalidToken.forEach((msg) => {
if (error.message.includes(msg)) {
hasAuthError = true;
}
});
gregone marked this conversation as resolved.
Show resolved Hide resolved

if (error.message.includes(ErrInvalidToken)) {
if (hasAuthError) {
this.session.invalidate();
this.transitionTo('auth');
}
Expand Down
22 changes: 22 additions & 0 deletions ui/tests/acceptance/auth-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';

import login from 'waypoint/tests/helpers/login';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';

module('Acceptance | auth', function (hooks: NestedHooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('redirects to /auth from authenticated routes when logged out', async function (assert) {
await visit(`/default`);
assert.equal(currentURL(), `/auth`);
});

test('does not redirect to /auth from authenticated routes when logged in', async function (assert) {
await login();
await visit(`/default`);
assert.equal(currentURL(), `/default`);
});
});
Comment on lines +8 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!