Files
threshold-ui/ui/admin/app/services/session.js
T
2024-05-31 11:29:24 -07:00

28 lines
803 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import BaseSessionService from 'ember-simple-auth/services/session';
import { inject as service } from '@ember/service';
import { formatDbName } from 'api/services/indexed-db';
export default class SessionService extends BaseSessionService {
@service indexedDb;
@service('browser/window') window;
/**
* Extend ember simple auth's handleAuthentication method
* so we can hook in and setup the DB after a successful authentication
*/
handleAuthentication() {
super.handleAuthentication(...arguments);
const userId = this.data?.authenticated?.user_id;
const hostUrl = this.window.location.host;
if (userId && hostUrl) {
this.indexedDb.setup(formatDbName(userId, hostUrl));
}
}
}