Merge branch 'bvander/worker-thread-auth-hack' into 'master'
workaround for getting the token in the web worker See merge request grassrootseconomics/cic-staff-client!45
This commit is contained in:
commit
742c589835
@ -10,4 +10,4 @@ export * from '@app/_helpers/read-csv';
|
||||
export * from '@app/_helpers/schema-validation';
|
||||
export * from '@app/_helpers/sync';
|
||||
export * from '@app/_helpers/online-status';
|
||||
export * from './to-hex';
|
||||
export * from '@app/_helpers/to-hex';
|
||||
|
@ -219,18 +219,21 @@ export class UserService {
|
||||
if (typeof Worker !== 'undefined') {
|
||||
const worker = new Worker('@app/_workers/fetch-accounts.worker', { type: 'module' });
|
||||
worker.onmessage = ({ data }) => {
|
||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||
if (status) {
|
||||
data.balance = await this.tokenService.getTokenBalance(
|
||||
data.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0]
|
||||
);
|
||||
}
|
||||
});
|
||||
this.addAccount(data, limit);
|
||||
if (data) {
|
||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||
if (status) {
|
||||
data.balance = await this.tokenService.getTokenBalance(
|
||||
data.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0]
|
||||
);
|
||||
}
|
||||
});
|
||||
this.addAccount(data, limit);
|
||||
}
|
||||
};
|
||||
worker.postMessage({
|
||||
addresses: accountAddresses.slice(offset, offset + limit),
|
||||
url: environment.cicMetaUrl,
|
||||
token: sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN')),
|
||||
});
|
||||
} else {
|
||||
this.loggingService.sendInfoLevelMessage(
|
||||
|
@ -8,6 +8,7 @@ import * as vCard from 'vcard-parser';
|
||||
const headers = {
|
||||
'x-cic-automerge': 'client',
|
||||
};
|
||||
|
||||
const options = {
|
||||
headers,
|
||||
};
|
||||
@ -16,17 +17,23 @@ addEventListener('message', async ({ data }) => {
|
||||
if (data.addresses instanceof Array) {
|
||||
for (const accountAddress of data.addresses) {
|
||||
try {
|
||||
const account = await getAccountByAddress(accountAddress, data.url);
|
||||
const account = await getAccountByAddress(accountAddress, data.url, data.token);
|
||||
postMessage(account);
|
||||
} catch (error) {
|
||||
throw Error(error);
|
||||
console.log(`ERROR we failed to get account ${accountAddress}`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function getAccountByAddress(accountAddress: string, metaUrl: string): Promise<any> {
|
||||
async function getAccountByAddress(
|
||||
accountAddress: string,
|
||||
metaUrl: string,
|
||||
token: string,
|
||||
): Promise<any> {
|
||||
const userKey = await User.toKey(add0x(accountAddress));
|
||||
|
||||
headers['Authorization'] = 'Bearer ' + token;
|
||||
const response = await fetch(`${metaUrl}/${userKey}`, options)
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
|
Loading…
Reference in New Issue
Block a user