0
블로그 앱을 만들고 있습니다. 각 사용자는 아이디어를 게시 할 수 있으며 게시 된 사용자 만 게시물을 삭제하거나 업데이트 할 수 있습니다.몽구스에서 사용자 액세스 제어에 오류가 있습니다.
exports.verifyOwn = function (req, res, next) {
if (User._id === req.decoded._doc.postedBy) {
next();
} else {
var err = new Error('You do not have administrative privileges!');
err.status = 401;
return next(err);
}
}
이 내 인증 코드. 내가 어떻게 자신의 사용자
var postSchema = new Schema({
title:{
type:String,
required:true
},
image:{
type:String,
required:true
},
meta:{
type:String,
required:true
},
story:{
type:String,
required:true
},
likes:{
type:Number,
min:0,
required:true
},
postedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
comments:[commentSchema]
},
{
timestamps: true
});
을하여 게시물을 delte 할 수 있는지 확인이 내 사용자 스키마입니다 수
var User = new Schema({
username: String,
password: String,
OauthId: String,
OauthToken: String,
firstname: {
type: String,
default: ''
},
lastname: {
type: String,
default: ''
},
biodata: {
type: String,
default: ''
},
admin:{
type: Boolean,
default: false
}
});