• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

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

20.01.05 14:38 작성 조회수 127

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',

답변 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

꼬부기님의 프로필

꼬부기

질문자

2020.01.05

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

0

꼬부기님의 프로필

꼬부기

질문자

2020.01.05

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