vault/ui/app/components/token-expire-warning.js
Angel Garbarino 44af0978e6
Replace all service injects with updated import syntax (#25367)
* replace all injects with import syntax

* Delete ui/app/components/identity/_popup-base.js
2024-02-13 10:00:31 -07:00

52 lines
1.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { later } from '@ember/runloop';
import { task } from 'ember-concurrency';
export default class TokenExpireWarning extends Component {
@service auth;
@service router;
@tracked canDismiss = true;
handleRenew() {
return new Promise((resolve) => {
later(() => {
this.auth
.renew()
.then(() => {
// This renewal was triggered by an explicit user action,
// so this will reset the time inactive calculation
this.auth.setLastFetch(Date.now());
})
.finally(() => {
resolve();
});
}, 200);
});
}
@task
*renewToken() {
yield this.handleRenew();
}
get queryParams() {
// Bring user back to current page after login
return { redirect_to: this.router.currentURL };
}
get showWarning() {
const currentRoute = this.router.currentRouteName;
if ('vault.cluster.oidc-provider' === currentRoute) {
return false;
}
return !!this.args.expirationDate;
}
}