1
0
Fork 0
mirror of https://github.com/cheeaun/phanpy.git synced 2025-05-01 04:41:57 +03:00

Apply auth for remote-instance API calls

This commit is contained in:
Lim Chee Aun 2023-12-23 23:07:08 +08:00
parent 6703b27bfb
commit 8ca768b957
2 changed files with 22 additions and 0 deletions
src/utils

View file

@ -4,6 +4,7 @@ import store from './store';
import {
getAccount,
getAccountByAccessToken,
getAccountByInstance,
getCurrentAccount,
saveAccount,
} from './store-utils';
@ -249,6 +250,22 @@ export function api({ instance, accessToken, accountID, account } = {}) {
};
}
const instanceAccount = getAccountByInstance(instance);
if (instanceAccount) {
const accessToken = instanceAccount.accessToken;
const client =
accountApis[instance]?.[accessToken] ||
initClient({ instance, accessToken });
const { masto, streaming } = client;
return {
masto,
streaming,
client,
authenticated: true,
instance,
};
}
const client = apis[instance] || initClient({ instance });
const { masto, streaming, accessToken } = client;
return {