如何在羽毛Vuex auth service中设置idField



我有一个很长一段时间都无法解决的问题。 我正在使用feathersJS作为后端api和Vue.js在前面和Mongodb上制作一个商店。当我尝试在网站上对用户进行身份验证时,一切都很顺利,直到"setUser"操作触发,并且在身份验证服务获取器中,我收到一条错误消息,指出"无法读取未定义的属性'idField'"。我相信我尽可能地将此属性更改为"_id",但仍然发生此错误。这里有一些截图,可能会有所帮助。这个项目应该让我在webDev中获得第一份工作,所以我将永远感谢您的支持。

vuex 中的添加项操作,

在 vuex 中设置用户操作

羽毛客户端.js:

import feathers from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio-client';
import auth from '@feathersjs/authentication-client';
import io from 'socket.io-client';
import { iff, discard } from 'feathers-hooks-common';
import feathersVuex from 'feathers-vuex';
const socket = io('http://localhost:3030', { transports: ['websocket'] });
const feathersClient = feathers()
.configure(socketio(socket))
.configure(auth({ storage: window.localStorage, debug: false }))
.hooks({
before: {
all: [
iff(
context => ['create', 'update', 'patch'].includes(context.method),
discard('__id', '__isTemp'),
),
],
},
});
export default feathersClient;
// Setting up feathers-vuex
const {
makeServicePlugin, makeAuthPlugin, BaseModel, models, FeathersVuex,
} = feathersVuex(
feathersClient,
{
idField: '_id', // Must match the id field in your database table/collection
whitelist: ['$regex', '$options'],
},
);
export {
makeAuthPlugin, makeServicePlugin, BaseModel, models, FeathersVuex,
};

身份验证服务文件:

import { makeAuthPlugin } from '../../feathers-client';
export default makeAuthPlugin({
userService: 'api/users',
entityIdField: '_id',
});

这里的问题是服务的名称,作为 vuex 中的插件,它的名称是"用户"而不是"api/users"。解决方案是更改服务插件选项名称样式:"路径"而不是"短">

最新更新