我正在使用Loopback 3,我的数据源是MySQl。我创建了一个具有SUPER_ADMIN角色的用户。表格中的条目如下所示:
用户表如下所示:
1 admin password admin@admin.com
角色表如下所示:
3 ADMIN super admin 4/24/18 11:42 AM 4/24/18 11:42 AM
角色扮销表
4 ADMIN 1 3
但是当我尝试在ACL中使用此角色时,它不起作用:
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "ADMIN",
"permission": "ALLOW",
"property": "greet"
}
上面总是抛出401,Authorization Required错误。
如果我在这里遗失任何东西,有人可以告诉我。
由于
答案 0 :(得分:1)
// other import
import {Query} from “Apollo-graphql”; // new Query Component
import gql from "graphql-tag";
import { graphql } from "react-apollo";
import UserComponent from '../component/UserComponent'; // any component to display query result
const GET_ALL_USER = gql`
{
allUsers: {
firstname,
lastname,
username,
# other information
}
}
`
const UPDATE_USER_STATUS = gql`
mutation UpdateUserStatus($userID: ID!, $status: Int!){
updateUserState(userID: $userID, status: $status){
firstname,
lastname
username
# other information
}
}
`
ExampleComponent extends React.Component{
onEditInformation = async (user) => {
const response = await mutate({
variables: {userID: user}
})
}
render(){
return(
<Query query={GET_ALL_USER}>
{({data: { allUsers }}) => {
return allusers.map(user => {
return (
<UserComponent
user={user}
onEdit={() => this.onEditInformation(user)}
/>
)
})
}}
</Query>
)
}
}
export default graphql(UPDATE_USER_STATUS)(ExampleComponent);
条目中 principalType
值有误,RoleMapping
应替换为ADMIN
,这是常量:USER