bigbuffet-rw/app/soapbox/utils/scopes.ts

31 lines
731 B
TypeScript
Raw Normal View History

import { PLEROMA, parseVersion } from './features';
2023-01-25 14:32:59 -08:00
import type { RootState } from 'soapbox/store';
import type { Instance } from 'soapbox/types/entities';
/**
* Get the OAuth scopes to use for login & signup.
* Mastodon will refuse scopes it doesn't know, so care is needed.
*/
2023-01-25 14:32:59 -08:00
const getInstanceScopes = (instance: Instance) => {
const v = parseVersion(instance.version);
switch (v.software) {
case PLEROMA:
return 'read write follow push admin';
default:
return 'read write follow push';
}
};
2023-01-25 14:32:59 -08:00
/** Convenience function to get scopes from instance in store. */
const getScopes = (state: RootState) => {
return getInstanceScopes(state.instance);
};
export {
2023-01-25 14:32:59 -08:00
getInstanceScopes,
getScopes,
};