Files
threshold-ui/ui/desktop/app/services/session.js
T
2025-03-12 08:29:54 -07:00

30 lines
839 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { service } from '@ember/service';
import BaseSessionService from 'ember-simple-auth/services/session';
import { notifyError } from 'core/decorators/notify';
export default class SessionService extends BaseSessionService {
@service ipc;
/**
* Extend ember simple auth's handleAuthentication method
* so we can hook in and add the user's token to the cache daemon
*/
@notifyError(({ message }) => message, { catch: true })
async handleAuthentication() {
super.handleAuthentication(...arguments);
if (this.session.isAuthenticated) {
const sessionData = this.data?.authenticated;
await this.ipc.invoke('addTokenToDaemons', {
tokenId: sessionData?.id,
token: sessionData?.token,
});
}
}
}