unresolved methods
562
작성한 질문수 1
안녕하세요
user.js에서
userSchema.pre
userScema.methods
var token = jwt.sign(user._id.toHexString(), secretToken) 에서
pre, methods, toHexString() 세 부분에 밑줄이 뜨며 unresolved methods or functions 등 unresolved 라는 에러가 뜹니다. 작동에는 오류가 없지만 왜 뜨는건지 궁금해서 질문드립니다.
웹스톰 사용하고 있고,
위의 사진과 같습니다.
감사합니다!!
//user.js
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const saltRounds = 10;
const jwt = require('jsonwebtoken');
const userSchema = new mongoose.Schema({
name: {
type: String,
maxlength: 50
},
email: {
type: String,
trim: true, //공백을 제거
unique: 1 //이메일은 하나. 유니크 했으면 좋겠음.
},
password: {
type: String,
minlength:5
},
lastname: {
type: String,
maxlength: 50
},
role: {
type: Number,
default: 0
},
image: String, //오브젝트를 사용하지 않고 이렇게 하나로 줘도 된다.
token: {
type: String //유효성 검사를 위해
},
tokenExp: {
type: Number //유효기간.
}
})
userSchema.pre('save', function(next){
//비밀번호를 암호화 시킨다
//index.js 의 save를 하기 전에, function을 하면서 암호화 시킨다.
//이때 salt를 이용해서 비밀번호를 암호화한다. 그 전에 salt를 먼저 생성해야함.
//saltround는 salt가 몇글자인지임
//genSalt: salt를 만든다.
var user = this; //this는 이때 위의 user 객체를 가리킨다.
if(user.isModified('password')){
bcrypt.genSalt(saltRounds, function(err, salt){
if (err) return next(err);
bcrypt.hash(user.password, salt, function (err, hash){
//user.password : this, 즉 객체의 password. 암호화 되기 전의 패스워드
//hash : 암호화된 비밀번호
//store hash in your password DB
if (err) return next(err)
user.password = hash
})
})
} else{
next()
}
next()
})
userSchema.methods.comparePassword = function(plainPassword, cb) {
//plainpassword와 암호화된 비밀번호가 같은지 확인하기 -> plainpassword를 암호화 해서 암호화한 password와 같은지 확인하기.
bcrypt.compare(plainPassword, this.password, function(err, isMatch){
if(err) return cb(err),
cb(null, isMatch)
})
}
userSchema.methods.generateToken = function(cb){
var user = this;
//jsonwebtoken을 이용해서 token을 생성하기
var token = jwt.sign(user._id.toHexString(), 'secretToken')
user.token = token
user.save(function(err, user){
if(err) return cb(err)
cb(null, user)
})
}
const User = mongoose.model('User', userSchema) //스키마를 모델로 감싸준다
module.exports = { User } //다른 파일에서도 쓸 수 있도록 export
답변 1
0
안녕하세요 ~! 웹스톰도 인터페이스가 깔끔한것 같네요 ~ ! 그런데 제가 웹스톰을 써본적이 없어서 ㅠㅠ
우선 구글링해보니
이런식에 글이 있더라구요 ~! 들어가서 따라해보시면 될 것 같습니다 ~ !
깃 이메일이랑 비번이 필요하다고 하네요
0
50
1
404 에러
0
120
1
34강 인증 체크에서 element 사용 때문에 에러나시는 분들 이렇게 하심 됩니다.
0
137
1
로그인, 로그아웃, 토근 작동 안 함
0
256
0
9강 오류 어떻게 해결하나요?
0
197
1
localhost 에서 연결을 거부했습니다.
0
1965
4
포스트맨에서 true가 안떠요
0
156
1
왜 안되나요
0
133
1
몽고db 연결 오류가 납니다 위에껀 입력한 코드, 아래껀 터미널이에요
0
248
1
로그아웃 401 에러(Unauthorized)
0
516
2
암호가 해싱되지 않고 입력값 그대로 db에 저장되는 문제
0
155
1
7강중에서
0
174
2
User.findByToken is not a function
0
215
1
루트 디렉토리
0
278
1
useState
0
569
1
프록시 잘 설정했는데도 404 오류 뜨는 분들
5
898
6
webpack 관련 에러 질문
0
225
1
리액트 관련 질문
0
282
1
14강 로그아웃 안됨
0
325
1
mongoDB 데이터 확인하는 법
0
414
1
postman 에러
0
296
1
선생님 리덕스를 사용하면 어떠한 부분이 좋은지 알 수 있을까요?
0
238
1
다음과 같은 에러들이 발생합니다.
0
282
1
14강 로그아웃 기능 구현시 postman에서 Cannot POST 오류가 뜹니다.
0
383
1





