I am working on creating a user-login system with Nodejs. I have a few questions that I can't seem to find the answer to (I'm using the Local Strategy using Passport).
1) Creating/Storing User Account
The passport documentation specify something like:
User.findOne({username: username }, function(err, user){
if(err){return done(err);}
if(!user){
return done(null, false, {message: "Incorrect Username."});
}
if(!user.validPassword(password)){
return done(null, false, {message: 'Incorrect Password.'});
}
return done(null, user);
});
or
passport.deserializeUser(function(id, done){
User.findById(id, function(err,user){
done(err, user);
});
});
I'm not sure where the "User" comes from as I am getting a "User is not defined" error when I attempt to login. I assume I need to make a database of some sort, but I'm not sure how to go about doing that (neither documentations nor online sources indicate the need to do this). What exactly is "User"?
How would I go about making a "create account" thing and storing the user-account to a (local) database?
2) Getting User Information / Storing User Information afterwards
After the user logs in, I need to get some specific data associated with that account, such as username. The users will also have a "ranking point" so I need a way to get that as well. When the user, let's say, "wins" in a game that I have, the user gains "ranking points" and I need to update that as well to the specific account. How would I do this? Is this done using Passport as well (or is Passport just for authentication?)
For the local strategy example here: https://github.com/passport/express-4.x-local-example
The users are hardcoded in the users.js file:
var records = [
{ id: 1, username: 'jack', password: 'secret', displayName: 'Jack', emails: [ { value: 'jack@example.com' } ] }
, { id: 2, username: 'jill', password: 'birthday', displayName: 'Jill', emails: [ { value: 'jill@example.com' } ] }
];
For an example of how to build an entire app see (this was already answered on SO here: Comprehensive tutorial for nodejs passport local-strategy setup?):
https://scotch.io/tutorials/easy-node-authentication-setup-and-local