yug95 / node-mysql

Node with mysql boilerplate
MIT License
76 stars 47 forks source link

Issue with JWT Login #4

Closed supracia closed 6 years ago

supracia commented 6 years ago

Everytime I try to login in Postman it returns this JSON:

{
    "error": {
        "statusCode": 422,
        "name": "ValidationError",
        "message": "Unprocessable Entity",
        "details": {
            "context": "authentic",
            "codes": [
                "USERNAME_REQUIRED"
            ],
            "messages": [
                {
                    "USERNAME_REQUIRED": "should have required property 'username'"
                }
            ]
        }
    }
}

I'm using MySQL database that I created manually like this:

CREATE TABLE `User` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` int(11) DEFAULT NULL,
  `CreatedDate` datetime DEFAULT NULL,
  `UpdatedDate` datetime DEFAULT NULL,
  `UpdatedBy` int(11) DEFAULT NULL,
  `IsEnabled` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

Here is a printscreen of how I am using it on Postman: captura de ecra 2018-08-02 as 11 30 28

Can someone help me out please?

yug95 commented 6 years ago

Please pass body as json parameter: { "username":"test", "password":"testpass" }

You are passing as form-url-encode instead use JSON format.it will work

supracia commented 6 years ago

Thank you for the answear, it resolved that problem. But now it's showing this errors. Is it because of the connection to the database or did I not created the table correctly?

captura de ecra 2018-08-02 as 14 38 55

yug95 commented 6 years ago

sorry my bad i have forgotten to add in ReadMe file , first there is a signup route which will ask for username and password and convert your password in encrypted pass and save in DB , later when you call login route and give username and password it will bring DB password for specific id and decode and check whether is correct or not. so if you are saving manually it wont work. i hope you get it. @supracia

supracia commented 6 years ago

Oh of course, by bad sorry. Thank you!