Files
threshold-ui/ui/admin/app/routes/scopes/index.js
T

35 lines
884 B
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-07-24 19:12:20 -04:00
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
export default class ScopesIndexRoute extends Route {
// =services
@service session;
@service router;
2020-07-24 19:12:20 -04:00
// =methods
/**
* If authenticated, redirects to the scope route of the authenticted scope.
* If unauthenticated, redirects to the first scope that was loaded (if any).
* @param {[ScopeModel]} model
* @param {?ScopeModel} model.firstObject
*/
redirect() {
2020-07-29 15:47:23 -04:00
const authenticatedScopeID = get(
this.session,
'data.authenticated.scope.id'
);
2020-07-24 19:12:20 -04:00
if (authenticatedScopeID) {
this.router.transitionTo('scopes.scope', authenticatedScopeID);
} else {
this.router.transitionTo('scopes.scope', 'global');
2020-07-24 19:12:20 -04:00
}
}
}