Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth plugin fails to generate the getters when userService contains a path-like name, e.g 'v1/users' #613

Open
FrancescoEnea opened this issue Nov 22, 2021 · 0 comments

Comments

@FrancescoEnea
Copy link

FrancescoEnea commented Nov 22, 2021

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.

DevTools screenshot

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant