inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Vue로 Nodebird SNS 만들기

500로 회원가입이 되지 않습니다.

211

꼬부기

작성한 질문수 13

0

안녕하세요.

현재 백엔드 서버, 프론드서버를 모두 npm run dev로 킨 상태입니다. 또한 msSQL 도 running을 확인했습니다.

workbench를 통해 user 테이블이 생성된 것 까지 확인된 상태입니다.

회원가입을 하게 되면, terminal 창에 아래와 같은 500에러가 발생합니다.

백엔드에서도 console.log로 이메일, 패스워드를 찍었는데, undefined가 되어있어서 데이터가 안 넘어가는 상태로 생각하고 있습니다. (프론트에서는 payload에 값이 다 잘 들어있습니다.)

무엇이 문제인지 알고싶습니다.

Executing (default): SELECT `id`, `email`, `nickname`, `password`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`email` = 'dog@dog.dog';

{ SequelizeValidationError: notNull Violation: User.email cannot be null,

notNull Violation: User.nickname cannot be null,

notNull Violation: User.password cannot be null

  name: 'SequelizeValidationError',

nodejs vuex vuejs aws mysql ssr

답변 4

1

제로초(조현영)

db.User.create에는 where 넣지말고 바로 값 넣으셔야 합니다.

await db.User.create({

        email: req.body.email,

        password: hash,

        nickname: req.body.nickname
   });

1

제로초(조현영)

POST /user 라우터에서 req.body.email, req.body.password가 undefined였다는 말씀이신가요? 그런 경우는 express.json(), express.urlencoded() 설정이 제대로 되어있는지 봐야 합니다.

0

꼬부기

넵!감사합니다. 정상적으로 실행이됩니다. 감사합니다!!

0

꼬부기

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.post('/user'async (reqresnext=> {
  try {
    console.log('reqqqqqqqqqqqqq'req.body)
    const hash = await bcrypt.hash(req.body.password12)
    const exUser = await db.User.findOne({
      where: {
        email: req.body.email,
      }
    })
    if (exUser) {
      return res.status(403).json({
        errorCode: 1,
        message: '이미 회원가입이 되어있어요'
      })
   }
    const newUser =  await db.User.create({
      where: {
        email: req.body.email,
        password: hash,
        nickname: req.body.nickname
      } 
    });
    res.status(201).json(newUser)
  } catch (err) {
    console.log(err);
    return next(err);
  }
})

위의 코드로 실행을 하면, 아래와 같이 req.body에 값이 정상적으로 들어가있습니다.

그런데 바로 밑에 User.email cannot be null,가 되면 안된다는 에러가 발생합니다.

reqqqqqqqqqqqqq { email: 'dog@dog.dog',

  nickname: '강아지',

  password: 'q1w2e3r41234' }

Executing (default): SELECT `id`, `email`, `nickname`, `password`, `createdAt`, `updatedAt` FROM 

`Users` AS `User` WHERE `User`.`email` = 'dog@dog.dog';

{ SequelizeValidationError: notNull Violation: User.email cannot be null,

notNull Violation: User.nickname cannot be null,

notNull Violation: User.password cannot be null

npm run dev 할 때 에러가 발생합니다.

0

144

1

해당 강의는 리뉴얼 예정은 따로 없나요?

0

327

1

강의는 언제까지 업데이트 된 내용인가요?

0

328

2

실습 환경 문의(Node 버전)

0

364

1

로그인 새로고침시 풀림

0

290

1

안녕하세요! 로그인 유지 질문 드립니다!

0

402

1

웹 서버 관련해서 질문드립니다.

0

440

1

버전때매 질문 드립니다!!

0

312

1

이 강의는 vue3는 아닌가요??

0

371

1

vsCode에 관한 질문입니다

0

487

1

v.trim()이 타입에러가 뜹니다...

0

342

1

express.static('uploads')

0

342

2

STRING이 인식이 안되는데 이유알수있을까요?

0

445

2

<v-lsit-item-title> 에러

0

408

2

vue cli 를 실무에서도 사용하지 않으시나요?

0

318

1

선생님 처음 환경 셋팅 관련 문의드립니다.

0

384

1

nuxtServerInit 무한 로딩

0

974

3

Nginx Cookie 설정

0

720

2

상태가 204번인경우에는 어떻게 처리를 해야하나요?

0

291

1

선생님 nuxt 관련질문드립니다.

0

348

1

인덱스 비교로 삭제해도 될까요?

0

382

1

질문 드립니다!

0

331

2

안녕하세요

0

225

1

궁금한점이있습니다

0

235

1