Files
threshold-ui/ui/admin/app/services/session.js
T
Zhihe Li bd5e3da1f4 feat: 🎸 Initial setup of IndexedDB (#2064)
* feat: 🎸 Initial setup of IndexedDB

* fix: 🐛 Rethrow errors up from indexed db handler
2024-04-12 14:55:33 -04:00

23 lines
715 B
JavaScript

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.host;
if (userId && hostUrl) {
this.indexedDb.setup(formatDbName(userId, hostUrl));
}
}
}