과거 프로그래밍 자료들/React
kakao login notnull violation: user.email cannot be null 해결법
평부
2022. 8. 26. 17:48
* 상황 : 카카오로 로그인 하는 과정에서 오류가 생김
* 오류 원문
kakao notnull violation: user.email cannot be null, notnull violation: user.password cannot be null
kakao login notnull violation: user.email cannot be null
parent: Error: Field 'email' doesn't have a default value
* 문제 해결에 도움을 준 글
https://www.inflearn.com/questions/5623
* 수정 전 models/user.js
const Sequelize = require("sequelize");
module.exports = class User extends Sequelize.Model {
static init(sequelize) {
return super.init(
{
email: {
type: Sequelize.STRING(40),
allowNull: false,
unique: true,
},
nick: {
type: Sequelize.STRING(15),
allowNull: false,
},
password: {
type: Sequelize.STRING(100),
allowNull: false,
},
provider: {
type: Sequelize.STRING(10),
allowNull: false,
defaultValue: "local",
},
snsId: {
type: Sequelize.STRING(30),
allowNull: true,
},
},
{
sequelize,
timestamps: true,
underscored: false,
modelName: "User",
tableName: "users",
paranoid: true,
charset: "utf8",
collate: "utf8_general_ci",
}
);
}
static associate(db) {
db.User.hasMany(db.Post);
db.User.belongsToMany(db.User, {
foreignKey: "followingId",
as: "Followers",
through: "Follow",
});
db.User.belongsToMany(db.User, {
foreignKey: "followerId",
as: "Followings",
through: "Follow",
});
}
};
* 수정 후 models/user.js -> mysql에 있는 nodebird 테이블 삭제 -> npm start(nodemon app.js)로 재시작
-> 카카오로 로그인
const Sequelize = require("sequelize");
module.exports = class User extends Sequelize.Model {
static init(sequelize) {
return super.init(
{
email: {
type: Sequelize.STRING(40),
allowNull: true, //수정
unique: true,
},
nick: {
type: Sequelize.STRING(15),
allowNull: false,
},
password: {
type: Sequelize.STRING(100),
allowNull: true, //수정
},
provider: {
type: Sequelize.STRING(10),
allowNull: false,
defaultValue: "local",
},
snsId: {
type: Sequelize.STRING(30),
allowNull: true,
},
},
{
sequelize,
timestamps: true,
underscored: false,
modelName: "User",
tableName: "users",
paranoid: true,
charset: "utf8",
collate: "utf8_general_ci",
}
);
}
static associate(db) {
db.User.hasMany(db.Post);
db.User.belongsToMany(db.User, {
foreignKey: "followingId",
as: "Followers",
through: "Follow",
});
db.User.belongsToMany(db.User, {
foreignKey: "followerId",
as: "Followings",
through: "Follow",
});
}
};
* 전체 코드
https://github.com/ZeroCho/nodejs-book/tree/master/ch9/9.5/nodebird