2024-04-15 11:51:03 -05:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2024-02-05 15:59:58 -05:00
|
|
|
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;
|
2024-04-01 17:43:55 -04:00
|
|
|
const hostUrl = this.window.location.host;
|
2024-02-05 15:59:58 -05:00
|
|
|
if (userId && hostUrl) {
|
|
|
|
|
this.indexedDb.setup(formatDbName(userId, hostUrl));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|