I am trying to connect my frontend to my backend, I keep getting a internal 500 error when trying to connect my signin response to the backend sequelize postgres servers.
Here are the errors:
notNull Violation: User.username cannot be null,
notNull Violation: User.email cannot be null,
notNull Violation: User.password cannot be null
at InstanceValidator._validate (C:\Users\donal\videos\Web-Developement\videojs\yt-clone\yt-backend2\node_modules\sequelize\lib\instance-validator.js:50:13)
at async InstanceValidator._validateAndRunHooks (C:\Users\donal\videos\Web-Developement\videojs\yt-clone\yt-backend2\node_modules\sequelize\lib\instance-validator.js:60:7)
at async InstanceValidator.validate (C:\Users\donal\videos\Web-Developement\videojs\yt-clone\yt-backend2\node_modules\sequelize\lib\instance-validator.js:54:12)
at async User.save (C:\Users\donal\videos\Web-Developement\videojs\yt-clone\yt-backend2\node_modules\sequelize\lib\model.js:2360:7)
at async Function.create (C:\Users\donal\videos\Web-Developement\videojs\yt-clone\yt-backend2\node_modules\sequelize\lib\model.js:1336:12)
at async C:\Users\donal\videos\Web-Developement\videojs\yt-clone\yt-backend2\routes\auth.js:10:22 {
errors: [
ValidationErrorItem {
message: 'User.username cannot be null',
type: 'notNull Violation',
path: 'username',
value: null,
origin: 'CORE',
instance: [User],
validatorKey: 'is_null',
validatorName: null,
validatorArgs: []
},
ValidationErrorItem {
message: 'User.email cannot be null',
type: 'notNull Violation',
path: 'email',
value: null,
origin: 'CORE',
instance: [User],
validatorKey: 'is_null',
validatorName: null,
validatorArgs: []
},
ValidationErrorItem {
message: 'User.password cannot be null',
type: 'notNull Violation',
path: 'password',
value: null,
origin: 'CORE',
instance: [User],
validatorKey: 'is_null',
validatorName: null,
validatorArgs: []
Console Error from Inspect:
POST http://localhost:5000/api/auth/register 500 (Internal Server Error)
Here is my code: api.js
import axios from 'axios';
const apiClient = axios.create({
baseURL: "http://localhost:5000/api",
timeout: 1000,
});
export const authenticate = async (data) => {
try {
return await apiClient.post("/auth/register", data);
} catch (exception) {
return {
error: true,
exception,
};
}
};
auth from routes:
router.post('/register', async(req, res) => {
const { username, email, password } = req.body;
try {
const user = await User.create({ username, email, password });
const salt = await bcrypt.genSalt(10);
user.password = await bcrypt.hash(user.password, salt);
return res.json(user)
} catch (err) {
console.log(err)
return res.status(500).json(err)
};
});
My response body is coming from the signin component itself from my React frontend, not Postman. I think an issue it could be is that the server is not reconginizing it as json and still seeing it as html.