Auth plugin fails to generate the getters when userService contains a path-like name, e.g 'v1/users'
FrancescoEnea opened this issue · comments
Steps to reproduce
When feathersVuex is configured with nameStyle: 'short'
and the user service contains a path-like name, e.g v1/users
the authorization process fails to generate the getters (user
and isAuthenticated
) because it's unable to find the correct rootState.
The method makeAuthGetters
should take into consideration the nameStyle
(as makeServicePlugin
already does with makeNamespace
) and sanitize the passed data.
The error is Error: rootState[userService] is undefined
, within the file auth-module.getters
// auth-module.getters.js
[...]
const { idField } = rootState[userService]; // <--
const userId = state.user[idField];
return rootState[userService].keyedById[userId] || null;
[...]
Expected behavior
The authentication process should set the getters correctly.
makeAuthGetters
should access the nameStyle
option and transform the userService accordingly
For example:
// auth-module.getters.js
[...]
const correctUserService = userService.split('/').slice(-1);
const { idField } = rootState[correctUserService];
const userId = state.user[idField];
return rootState[correctUserService].keyedById[userId] || null;
[...]
Actual behavior
makeAuthGetters
tryes to access the rootState with a userService containing a slash charachter (e.g. rootState['v1/users']
), hence throwing an error.
System configuration
Module versions (especially the part that's not working):
"@feathersjs/authentication-client": "^4.5.11",
"@feathersjs/feathers": "^4.5.11",
"@feathersjs/socketio-client": "^4.5.11",
"@feathersjs/vuex": "^4.0.1-pre.16",
"@quasar/extras": "^1.12.1",
"feathers-hooks-common": "^5.0.6",
"quasar": "^2.0.0",
"socket.io-client": "^2.0.0",
"vue": "^3.2.22",
"vuex": "^4.0.1"
Vue.js DevTools 6.0.0.20
NodeJS version: v16.13.0
Operating System: Fedora Linux 35 (Workstation Edition)
Browser Version: Firefox 94
Module Loader: Webpack