ra-data-feathers icon indicating copy to clipboard operation
ra-data-feathers copied to clipboard

Disccussion about Permission

Open tanedward2101 opened this issue 2 years ago • 1 comments

Hi, need some help here. My authentication feathers return this.

{
    "accessToken": "",
    "authentication": {
        "strategy": "local",
        "accessToken": "",
        "payload": {

        }
    },
    "user": {
        "id": 10,
        "username": "John Doe",
        "roles": [
            "administrator",
            "another-role"
        ],
    }
}

And this is my authClientOption

const authClientOptions = {
  storageKey: 'feathers-jwt', // The key in localStorage used to store the authentication token
  authenticate: { // Options included in calls to Feathers client.authenticate
    strategy: 'local',
  },
  permissionsKey: 'permissions', // The key in localStorage used to store permissions from decoded JWT
  permissionsField: 'roles', // The key in the decoded JWT containing the user's role
  passwordField: 'password', // The key used to provide the password to Feathers client.authenticate
  usernameField: 'username', // The key used to provide the username to Feathers client.authenticate
  redirectTo: '/login', // Redirect to this path if an AUTH_CHECK fails. Uses the react-admin default of '/login' if omitted.
  logoutOnForbidden: true
};

One user can have multiple roles. Is there anyway to get that roles data? Somehow, I cannot retrieve roles data.

tanedward2101 avatar Aug 25 '21 11:08 tanedward2101

Permissions seems to be an array. Please check permissions content.

Anyway check react-admin auth doc: https://marmelab.com/react-admin/Authorization.html Exists usePermissions() hook, you can use it.

josx avatar Aug 26 '21 13:08 josx