2024-04-15 11:51:03 -05:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2024-04-15 11:51:03 -05:00
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2025-02-13 11:00:19 -05:00
|
|
|
async handleAuthentication() {
|
2024-02-05 15:59:58 -05:00
|
|
|
const userId = this.data?.authenticated?.user_id;
|
2025-02-13 11:00:19 -05:00
|
|
|
const hostUrl = this.window.location?.host;
|
2024-02-05 15:59:58 -05:00
|
|
|
if (userId && hostUrl) {
|
2025-02-13 11:00:19 -05:00
|
|
|
await this.indexedDb.setup(formatDbName(userId, hostUrl));
|
2024-02-05 15:59:58 -05:00
|
|
|
}
|
2025-02-13 11:00:19 -05:00
|
|
|
|
|
|
|
|
// We let ember-simple-auth handle transitioning back to the index after authentication.
|
|
|
|
|
// This route can be configured in our environment config.
|
|
|
|
|
super.handleAuthentication(...arguments);
|
2024-02-05 15:59:58 -05:00
|
|
|
}
|
|
|
|
|
}
|