Skip to content

Commit b068cd0

Browse files
committed
feat: use auth token for IPC calls.
1 parent 6608a2a commit b068cd0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

typescript-packages/loader/src/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Bootstrap {
1818
logger: import('@steambrew/client/build/logger').default;
1919
startTime: number;
2020
ctx: Context;
21+
millenniumAuthToken: string | undefined = undefined;
2122

2223
async init() {
2324
const loggerModule = await import('@steambrew/client/build/logger');
@@ -62,8 +63,14 @@ class Bootstrap {
6263
}
6364

6465
this.logger.log('Injecting Millennium frontend library...');
65-
Object.assign((window.MILLENNIUM_API ??= {}), await import('@steambrew/client'), await import('./millennium-api'));
6666

67+
const steambrewClientModule = await import('@steambrew/client');
68+
const millenniumApiModule = await import('./millennium-api');
69+
70+
/** Set Auth Token */
71+
millenniumApiModule.setMillenniumAuthToken(this.millenniumAuthToken);
72+
73+
Object.assign((window.MILLENNIUM_API ??= {}), steambrewClientModule, millenniumApiModule);
6774
this.logger.log('Millennium API injected successfully.', window.MILLENNIUM_API);
6875
}
6976

@@ -81,9 +88,11 @@ class Bootstrap {
8188
});
8289
}
8390

84-
async StartPreloader(port: number, shimList?: string[]) {
91+
async StartPreloader(port: number, millenniumAuthToken: string, shimList?: string[]) {
8592
await this.init();
8693

94+
this.millenniumAuthToken = millenniumAuthToken;
95+
8796
/** Setup IPC */
8897
window.MILLENNIUM_IPC_PORT = port;
8998
window.MILLENNIUM_IPC_SOCKET = await this.connectMillenniumBackend(port);
@@ -101,7 +110,10 @@ class Bootstrap {
101110
}
102111
case Context.Browser: {
103112
this.logger.log('Running in browser context...');
104-
window.MILLENNIUM_API = await import('./millennium-api');
113+
const millenniumApiModule = await import('./millennium-api');
114+
millenniumApiModule.setMillenniumAuthToken(this.millenniumAuthToken);
115+
116+
window.MILLENNIUM_API = millenniumApiModule;
105117

106118
const browserUtils = await import('./browser-init');
107119
await browserUtils.appendAccentColor();

typescript-packages/loader/src/millennium-api.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
1414
type IPC_types = string | number | boolean | Json;
1515
declare const g_PopupManager: any;
1616

17+
let millenniumAuthToken: string | undefined = undefined;
18+
19+
export function setMillenniumAuthToken(token: string) {
20+
millenniumAuthToken = token;
21+
}
22+
1723
const backendIPC = {
1824
postMessage: (messageId: number, contents: any): Promise<any> =>
1925
new Promise((resolve) => {
2026
const iteration = window.CURRENT_IPC_CALL_COUNT++;
21-
const message = { id: messageId, iteration, data: contents };
27+
const message = { id: messageId, iteration, data: contents, millenniumAuthToken };
28+
29+
if (!millenniumAuthToken) {
30+
console.warn('No Millennium auth token set. This will cause issues with IPC calls.');
31+
}
2232

2333
const handler = (event: MessageEvent) => {
2434
try {

0 commit comments

Comments
 (0)