[英]How can I check if current user is part of a sharepoint group with PnPJS?
I need to display content based on the group the current user belongs to but can't figure out how to do this in react/pnpjs.我需要根据当前用户所属的组显示内容,但不知道如何在 react/pnpjs 中执行此操作。
I wrote the function below but it returns false even when the group name returned in console.log(grp["Title"]) is correct.我在下面写了 function 但即使在 console.log(grp["Title"]) 中返回的组名是正确的,它也会返回 false。
private _checkUserInGroup(strGroup)
{
let InGroup:boolean = false;
let grp = sp.web.currentUser.groups.get().then((r: any) => {
r.forEach((grp: SiteGroups) =>{
if (grp["Title"] == strGroup)
{
InGroup = true;
}
console.log(grp["Title"]);
});
});
return InGroup;
}
Your request is pretty wide because we don't really know what you have tried.您的要求非常广泛,因为我们真的不知道您尝试了什么。
Step wise循序渐进
Which step is it that you are struggling with?您正在为哪一步而苦苦挣扎?
https://pnp.github.io/pnpjs/sp/site-users/ https://pnp.github.io/pnpjs/sp/site-users/
import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/site-users/web";
let groups = await sp.web.currentUser.groups();
Cheers干杯
Truez特鲁兹
I managed to make this work by placing async/await in the function...it was returning false before the call to sp.web.... Thanks a lot for the help.我设法通过在 function 中放置 async/await 来完成这项工作......它在调用 sp.web 之前返回 false ......非常感谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.