josx / ra-data-feathers

A feathers rest client for react-admin
MIT License
157 stars 58 forks source link

Disccussion about Permission #168

Open tanedward2101 opened 3 years ago

tanedward2101 commented 3 years ago

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.

josx commented 3 years ago

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.