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