Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit cb50173

Browse files
authored
Merge pull request #775 from derrabauke/fix-auth-stuff
fix(auth): improve invalid session handling
2 parents 06c8a8a + 439123a commit cb50173

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

app/adapters/application.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,23 @@ import OIDCJSONAPIAdapter from "ember-simple-auth-oidc/adapters/oidc-json-api-ad
1616
*/
1717
export default class ApplicationAdapter extends OIDCJSONAPIAdapter {
1818
@service session;
19+
@service router;
1920

2021
namespace = "api/v1";
2122

2223
get headers() {
2324
return { ...this.session.headers };
2425
}
26+
27+
handleResponse(status, ...args) {
28+
if (status === 401) {
29+
if (this.session.isAuthenticated) {
30+
this.session.invalidate();
31+
} else {
32+
this.router.transitionTo("login");
33+
}
34+
}
35+
36+
return super.handleResponse(status, ...args);
37+
}
2538
}

app/components/sy-topnav/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</LinkTo>
6666
</li>
6767
<li class="nav-top-list-item">
68-
<a href="#" data-test-logout {{on "click" (optional this.on-logout)}}>
68+
<a href="#" data-test-logout {{on "click" (optional @onLogout)}}>
6969
<FaIcon @icon="power-off" @prefix="fas" />
7070
Logout
7171
</a>

app/protected/controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ export default class ProtectedController extends Controller {
3030
* @public
3131
*/
3232
@action
33-
invalidateSession() {
33+
async invalidateSession() {
3434
this.autostartTour.done = [];
3535

36-
this.session.invalidate();
36+
await this.session.invalidate();
37+
3738
this.router.transitionTo("login");
3839
}
3940

app/protected/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<main class="page-main">
22
{{#if this.loading}}<span class="loader"></span>{{/if}}
33
<div class="page-content page-content--scroll">
4-
<SyTopnav @on-logout={{this.invalidateSession}} />
4+
<SyTopnav @onLogout={{this.invalidateSession}} />
55

66
{{outlet}}
77
</div>

0 commit comments

Comments
 (0)