workaround for getting the token in the web worker
This commit is contained in:
parent
a4813152ed
commit
7ae0413991
@ -10,4 +10,4 @@ export * from '@app/_helpers/read-csv';
|
|||||||
export * from '@app/_helpers/schema-validation';
|
export * from '@app/_helpers/schema-validation';
|
||||||
export * from '@app/_helpers/sync';
|
export * from '@app/_helpers/sync';
|
||||||
export * from '@app/_helpers/online-status';
|
export * from '@app/_helpers/online-status';
|
||||||
export * from './to-hex';
|
export * from '@app/_helpers/to-hex';
|
||||||
|
@ -219,6 +219,7 @@ export class UserService {
|
|||||||
if (typeof Worker !== 'undefined') {
|
if (typeof Worker !== 'undefined') {
|
||||||
const worker = new Worker('@app/_workers/fetch-accounts.worker', { type: 'module' });
|
const worker = new Worker('@app/_workers/fetch-accounts.worker', { type: 'module' });
|
||||||
worker.onmessage = ({ data }) => {
|
worker.onmessage = ({ data }) => {
|
||||||
|
if (data) {
|
||||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||||
if (status) {
|
if (status) {
|
||||||
data.balance = await this.tokenService.getTokenBalance(
|
data.balance = await this.tokenService.getTokenBalance(
|
||||||
@ -227,10 +228,12 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.addAccount(data, limit);
|
this.addAccount(data, limit);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
worker.postMessage({
|
worker.postMessage({
|
||||||
addresses: accountAddresses.slice(offset, offset + limit),
|
addresses: accountAddresses.slice(offset, offset + limit),
|
||||||
url: environment.cicMetaUrl,
|
url: environment.cicMetaUrl,
|
||||||
|
token: sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN')),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.loggingService.sendInfoLevelMessage(
|
this.loggingService.sendInfoLevelMessage(
|
||||||
|
@ -8,6 +8,7 @@ import * as vCard from 'vcard-parser';
|
|||||||
const headers = {
|
const headers = {
|
||||||
'x-cic-automerge': 'client',
|
'x-cic-automerge': 'client',
|
||||||
};
|
};
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
@ -16,17 +17,23 @@ addEventListener('message', async ({ data }) => {
|
|||||||
if (data.addresses instanceof Array) {
|
if (data.addresses instanceof Array) {
|
||||||
for (const accountAddress of data.addresses) {
|
for (const accountAddress of data.addresses) {
|
||||||
try {
|
try {
|
||||||
const account = await getAccountByAddress(accountAddress, data.url);
|
const account = await getAccountByAddress(accountAddress, data.url, data.token);
|
||||||
postMessage(account);
|
postMessage(account);
|
||||||
} catch (error) {
|
} 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));
|
const userKey = await User.toKey(add0x(accountAddress));
|
||||||
|
|
||||||
|
headers['Authorization'] = 'Bearer ' + token;
|
||||||
const response = await fetch(`${metaUrl}/${userKey}`, options)
|
const response = await fetch(`${metaUrl}/${userKey}`, options)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
Loading…
Reference in New Issue
Block a user