fix: 🐛 Add error notification if adding token to daemon fails (#2127)

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12488
This commit is contained in:
Zhihe Li authored and GitHub committed 2024-02-05 14:21:13 -05:00
1 parent 056008e13e
commit f8b5dcd824
2 files changed
+7 -3

No files matched your search

+3 -1
View File
@@ -8,6 +8,7 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { A } from '@ember/array';
import { getOwner } from '@ember/application';
import { notifyError } from 'core/decorators/notify';
export default class ApplicationRoute extends Route {
// =services
@@ -29,6 +30,7 @@ export default class ApplicationRoute extends Route {
* reported by the main process. If they differ, update the main process
* clusterUrl so that the renderer's CSP can be rewritten to allow requests.
*/
@notifyError(({ message }) => message, { catch: true })
async beforeModel() {
this.intl.setLocale(['en-us']);
await this.session.setup();
@@ -39,7 +41,7 @@ export default class ApplicationRoute extends Route {
// Add token to client daemon after a successful authentication restoration
if (this.session.isAuthenticated) {
const sessionData = this.session.data?.authenticated;
this.ipc.invoke('addTokenToClientDaemon', {
await this.ipc.invoke('addTokenToClientDaemon', {
tokenId: sessionData?.id,
token: sessionData?.token,
});
+4 -2
View File
@@ -5,6 +5,7 @@
import { inject as 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;
@@ -13,12 +14,13 @@ export default class SessionService extends BaseSessionService {
* Extend ember simple auth's handleAuthentication method
* so we can hook in and add the user's token to the client daemon
*/
handleAuthentication() {
@notifyError(({ message }) => message, { catch: true })
async handleAuthentication() {
super.handleAuthentication(...arguments);
if (this.session.isAuthenticated) {
const sessionData = this.data?.authenticated;
this.ipc.invoke('addTokenToClientDaemon', {
await this.ipc.invoke('addTokenToClientDaemon', {
tokenId: sessionData?.id,
token: sessionData?.token,
});