2024-01-22 12:12:44 -05:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2024-01-22 12:12:44 -05:00
|
|
|
*/
|
|
|
|
|
|
2023-11-09 13:20:20 -05:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
import BaseSessionService from 'ember-simple-auth/services/session';
|
2024-02-05 14:21:13 -05:00
|
|
|
import { notifyError } from 'core/decorators/notify';
|
2023-11-09 13:20:20 -05:00
|
|
|
|
|
|
|
|
export default class SessionService extends BaseSessionService {
|
|
|
|
|
@service ipc;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extend ember simple auth's handleAuthentication method
|
2024-06-17 17:16:07 -04:00
|
|
|
* so we can hook in and add the user's token to the cache daemon
|
2023-11-09 13:20:20 -05:00
|
|
|
*/
|
2024-02-05 14:21:13 -05:00
|
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
|
|
|
async handleAuthentication() {
|
2023-11-09 13:20:20 -05:00
|
|
|
super.handleAuthentication(...arguments);
|
|
|
|
|
|
|
|
|
|
if (this.session.isAuthenticated) {
|
|
|
|
|
const sessionData = this.data?.authenticated;
|
2024-05-28 15:24:43 -04:00
|
|
|
await this.ipc.invoke('addTokenToDaemons', {
|
2023-11-09 13:20:20 -05:00
|
|
|
tokenId: sessionData?.id,
|
|
|
|
|
token: sessionData?.token,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|