sb-mig
Version:
CLI to rule the world. (and handle stuff related to Storyblok CMS)
24 lines (23 loc) • 714 B
JavaScript
import { getAllSpaces } from "../spaces/spaces.js";
export const getCurrentUser = async (config) => {
const { sbApi } = config;
console.log("Trying to get current user current OAuthToken");
const currentUser = await sbApi
.get(`users/me`, {
per_page: 100,
})
.then((res) => {
return res.data.user;
})
.catch((err) => {
console.error(err);
return err;
});
return currentUser;
};
export const hasAccessToSpace = async (args, config) => {
const { spaceId } = args;
const allSpaces = await getAllSpaces(config);
const hasAccess = allSpaces.find((space) => Number(space.id) === Number(spaceId));
return !!hasAccess;
};