current user data
-
here im trying to get the current user uid via api: async function getCurrUserUid() {
try {
const currentUserData = await axios.get('http://localhost:4567/api/self');
const currentUserID = currentUserData.data.uid;
return (currentUserID);
} catch (error) {
console.error(error);
}
}call in my plugins module however i get port: 4567,
address: '127.0.0.1',
syscall: 'connect',
code: 'ECONNREFUSED',
errno: -61,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
}, -
@baris it is located in plugins module index.js however my whole intention is to restrict the plugins that are being loaded for admin and simple-admin(i create a group role called simple-admin), as an example for admins i wanna load all the plugins in the dropdown menu in plugins ACP but for simple admins only one or two plugins, that's why i wanna get the current user uid first and then check if it is an admin, load all the plugins, but if it was a simple admin filter them based on my requirements.
do you recommend any other approach or this is fine and i need to make some modifications?
-
In that case you can use the hook
filter:middleware.renderAdminHeader
this is fired when we are building the admin header which includes the plugins dropdown. Inside the hook you can look at thehookDatar.req.uid
to get theuid
of the user making the request. Below is a sample:myPlugin.filterMiddlewareRenderAdminHeader = async (hookData) => { console.log(hookData.req.uid, hookData.templateData.plugins); // TODO: filter plugins in `hookData.templateData.plugins` based on hookData.req.uid return hookData; }