pleroma/packages/pl-fe/src/utils/scopes.ts
marcin mikołajczak 859149230e pl-fe: cleanup, avoid parsing schemas more than once
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-09-01 15:36:24 +02:00

28 lines
739 B
TypeScript

import { getFeatures, PLEROMA, TOKI, type Instance } from 'pl-api';
import type { RootState } from 'pl-fe/store';
/**
* Get the OAuth scopes to use for login & signup.
* Mastodon will refuse scopes it doesn't know, so care is needed.
*/
const getInstanceScopes = (instance: Instance) => {
const v = getFeatures(instance).version;
switch (v.software) {
case TOKI:
return 'read write follow push write:bites';
case PLEROMA:
return 'read write follow push admin';
default:
return 'read write follow push';
}
};
/** Convenience function to get scopes from instance in store. */
const getScopes = (state: RootState) => getInstanceScopes(state.instance);
export {
getInstanceScopes,
getScopes,
};