Skip to content

Commit

Permalink
Cleanup and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Apr 28, 2023
1 parent f557234 commit c8348cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 0 additions & 1 deletion web/app/controllers/authenticate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Controller from "@ember/controller";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import SessionService from "hermes/services/session";
import { dropTask } from "ember-concurrency";

Expand Down
17 changes: 12 additions & 5 deletions web/app/services/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export default class SessionService extends EmberSimpleAuthSessionService {
*/
@tracked tokenIsValid = true;

/**
* Whether the reauthentication message is shown.
* Dictates if we poll the back end for a 401.
* Set true when the user's session has expired.
* Set false when the user successfully reauthenticates.
*/
@tracked reauthenticationMessageIsShown = false;

/**
Expand Down Expand Up @@ -93,8 +99,8 @@ export default class SessionService extends EmberSimpleAuthSessionService {
}
);

// Set this to true to prevent additional HEAD requests.
// When the user successfully reauthenticates, this will be set back to false.
// Set this true to prevent additional HEAD requests.
// On successful reauth, this will be reset false.
this.reauthenticationMessageIsShown = true;
}

Expand All @@ -106,6 +112,7 @@ export default class SessionService extends EmberSimpleAuthSessionService {
* Triggers a flash message with a button to reauthenticate.
* Used when the user's session has expired, or when the user
* unsuccessfully attempts to reauthenticate.
* Functions in accordance with the `skip_google_auth` config.
*/
private showReauthMessage(
title: string,
Expand Down Expand Up @@ -146,12 +153,12 @@ export default class SessionService extends EmberSimpleAuthSessionService {
window.location.reload();
} else {
await this.authenticate("authenticator:torii", "google-oauth2-bearer");
console.log("wait");
}

this.flashMessages.clearMessages();

await timeout(Ember.testing ? 0 : 1000);
// Wait a bit to show the success message.
await timeout(Ember.testing ? 0 : 1500);

this.flashMessages.add({
title: "Login successful",
Expand All @@ -165,9 +172,9 @@ export default class SessionService extends EmberSimpleAuthSessionService {
destroyOnClick: true,
});

// Reset the local parameters.
this.preventReauthenticationMessage = false;
this.reauthenticationMessageIsShown = false;

this.pollForExpiredAuth.perform();
} catch (error: unknown) {
this.flashMessages.clearMessages();
Expand Down

0 comments on commit c8348cc

Please sign in to comment.