Skip to content

Commit

Permalink
Merge pull request #53 from fleetbase/dev-v0.2.18
Browse files Browse the repository at this point in the history
Dev v0.2.18
  • Loading branch information
roncodes authored Sep 10, 2024
2 parents 6126265 + 332e595 commit ecb18f4
Show file tree
Hide file tree
Showing 6 changed files with 540 additions and 126 deletions.
22 changes: 14 additions & 8 deletions addon/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import SimpleAuthSessionService from 'ember-simple-auth/services/session';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { later } from '@ember/runloop';
import { debug } from '@ember/debug';
import getWithDefault from '../utils/get-with-default';

export default class SessionService extends SimpleAuthSessionService {
@service router;
@service currentUser;
@service fetch;
@service notifications;

/**
* Set where to transition to
Expand Down Expand Up @@ -52,22 +54,26 @@ export default class SessionService extends SimpleAuthSessionService {
}

const loaderNode = this.showLoader('Starting session...');
this.isLoaderNodeOpen = true;

try {
await this.router.transitionTo(this.redirectTo);
const removeLoaderNode = () => {
later(
this,
() => {
// remove node from body
document.body.removeChild(loaderNode);
this.isLoaderNodeOpen = false;
},
600 * 6
600 * 3
);
};
this.isLoaderNodeOpen = true;

try {
await this.router.transitionTo(this.redirectTo);
} catch (error) {
this.notifications.serverError(error);
debug(`Session's handleAuthentication() failed to transition: ${error.message}`);
}

removeLoaderNode();
}

/**
Expand Down Expand Up @@ -114,6 +120,7 @@ export default class SessionService extends SimpleAuthSessionService {
if (transition) {
transition.abort();
}

await invalidateWithLoader(error.message ?? 'Session authentication failed...');
throw error;
}
Expand Down Expand Up @@ -154,8 +161,7 @@ export default class SessionService extends SimpleAuthSessionService {
}

const loaderNode = this.showLoader(loadingMessage);

this.isLoaderNodeOpen = false;
this.isLoaderNodeOpen = true;

return this.session.invalidate().then(() => {
later(
Expand Down
2 changes: 1 addition & 1 deletion addon/services/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ThemeService extends Service {
*/
get router() {
const owner = getOwner(this);
const router = owner.lookup('service:router');
const router = owner.lookup('router:main');

return router;
}
Expand Down
Loading

0 comments on commit ecb18f4

Please sign in to comment.