open-vault/ui/app/components/auth-info.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

60 lines
1.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { later } from '@ember/runloop';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
/**
* @module AuthInfo
*
* @example
* ```js
* <AuthInfo @activeClusterName={{cluster.name}} @onLinkClick={{action "onLinkClick"}} />
* ```
*
* @param {string} activeClusterName - name of the current cluster, passed from the parent.
* @param {Function} onLinkClick - parent action which determines the behavior on link click
*/
export default class AuthInfoComponent extends Component {
@service auth;
@service router;
@tracked fakeRenew = false;
get hasEntityId() {
// root users will not have an entity_id because they are not associated with an entity.
// in order to use the MFA end user setup they need an entity_id
return !!this.auth.authData.entity_id;
}
get isRenewing() {
return this.fakeRenew || this.auth.isRenewing;
}
transitionToRoute() {
this.router.transitionTo(...arguments);
}
@action
renewToken() {
this.fakeRenew = true;
later(() => {
this.auth.renew().then(() => {
this.fakeRenew = this.auth.isRenewing;
});
}, 200);
}
@action
revokeToken() {
this.auth.revokeCurrentToken().then(() => {
this.transitionToRoute('vault.cluster.logout');
});
}
}