mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-21 16:55:25 +03:00
Apply auth for remote-instance API calls
This commit is contained in:
parent
6703b27bfb
commit
8ca768b957
2 changed files with 22 additions and 0 deletions
|
@ -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 {
|
||||
|
|
|
@ -10,6 +10,11 @@ export function getAccountByAccessToken(accessToken) {
|
|||
return accounts.find((a) => a.accessToken === accessToken);
|
||||
}
|
||||
|
||||
export function getAccountByInstance(instance) {
|
||||
const accounts = store.local.getJSON('accounts') || [];
|
||||
return accounts.find((a) => a.instanceURL === instance);
|
||||
}
|
||||
|
||||
export function getCurrentAccount() {
|
||||
if (!window.__IGNORE_GET_ACCOUNT_ERROR__) {
|
||||
// Track down getCurrentAccount() calls before account-based states are initialized
|
||||
|
|
Loading…
Reference in a new issue