Javascript 反应|无法发布| mongodb
我正在做一个论坛,直到现在一切都很有趣,至少我这么认为。。。 我进入了注册页面,做了所有这些,但是,当我从页面发送post请求时,它会导致服务器出错 错误:Javascript 反应|无法发布| mongodb,javascript,node.js,reactjs,mongodb,react-native,Javascript,Node.js,Reactjs,Mongodb,React Native,我正在做一个论坛,直到现在一切都很有趣,至少我这么认为。。。 我进入了注册页面,做了所有这些,但是,当我从页面发送post请求时,它会导致服务器出错 错误: (node:15264) UnhandledPromiseRejectionWarning: TypeError: user.issModified is not a function at model.<anonymous> (D:\discussa\server\models\User.js:18:15) a
(node:15264) UnhandledPromiseRejectionWarning: TypeError: user.issModified is not a function
at model.<anonymous> (D:\discussa\server\models\User.js:18:15)
at callMiddlewareFunction (D:\discussa\server\node_modules\kareem\index.js:483:23)
at model.next (D:\discussa\server\node_modules\kareem\index.js:58:7)
at _next (D:\discussa\server\node_modules\kareem\index.js:107:10)
at D:\discussa\server\node_modules\kareem\index.js:508:38
at processTicksAndRejections (internal/process/task_queues.js:75:11)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15264) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:15264) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate
the Node.js process with a non-zero exit code.
以下是输出:
虽然目前,我认为这没有任何用处,但它已经证明了某种web页面正在尝试路径
我至少检查了客户机和服务器50多次,我似乎无法理解这个问题,但我确实知道这与服务器的某种错误配置有关
下面是根目录和客户机目录的GitHub repo,因为它们不会在同一个repo中同时进行
如果需要用于创建客户端的模块,请确保在客户端目录中输入,然后执行以下操作:
npm install @testing-library/jest-dom @t@testing-library/user-event esting-library/react axios bcryptjs body-parser mongoose nodemon react react-dom react-router-dom react-scripts validator web-vitals
或
如果有人能做一些测试和调查,并能告诉我需要做什么/修复什么,我将不胜感激
另外,如果您确实测试了它,请确保在服务器目录中的.env文件中添加一个数据库密钥好的,我将把它放在那里,我是个白痴,我没有正确读取错误,我没有注意到我犯了一个非常愚蠢的错误,两个简单的打字错误。 现在都修好了 修复:server/models/User.js
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
name: String,
email: String,
password: String,
createdAt: {
defualt: Date.now(),
type: Date
},
role: String,
});
UserSchema.pre( 'save', async function (next) {
const user = this;
if (!user.issModified('passwprd')) return next();
^^^^^^^^^^^ ^^^^^^^^
// Changed to if (!user.issModified('passwprd')) return next();
const salt = await bcrypt.genSalt(10)
const hash = await bcrypt.hash(user.password, salt);
user.password = hash;
next()
});
const User = mongoose.model( 'User', UserSchema);
module.exports = User;
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
name: String,
email: String,
password: String,
createdAt: {
defualt: Date.now(),
type: Date
},
role: String,
});
UserSchema.pre( 'save', async function (next) {
const user = this;
if (!user.issModified('passwprd')) return next();
^^^^^^^^^^^ ^^^^^^^^
// Changed to if (!user.issModified('passwprd')) return next();
const salt = await bcrypt.genSalt(10)
const hash = await bcrypt.hash(user.password, salt);
user.password = hash;
next()
});
const User = mongoose.model( 'User', UserSchema);
module.exports = User;