ocastillo / nodejs-mysql-boilerplate

Very basic nodejs/express setup with mysql authentication.
MIT License
64 stars 18 forks source link

changing the name of the id field in mySQL breaks authentication. #1

Open dpouliot opened 10 years ago

dpouliot commented 10 years ago

Technically this is not an issue, since your code works when unaltered, but this is more of a procedural question. I'd like to point your project to a user database that already exists, but the id field is named userID. So as a test, I renamed the id field in your test database, then in /util/auth.js I

passport.serializeUser(function(user, done) {
    done(null, user.userID);
});

passport.deserializeUser(function(user_id, done) {
    new data.ApiUser({userID: user_id}).fetch().then(function(user) {
        return done(null, user);
    }, function(error) {
        return done(error);
    });
});

but when I run the code and attempt to log in, I get the error

error: failed to serialize user into session

and when I pause the script (using node-inspector) in passport.serializeUser I notice that user.id does not exist (though it does with your original project).

I'm hoping I'm just missing something simple. How can I change the name of id with this project? Thanks!