I'm trying to save a user that authenticated through GitHub into mongodb. I'm using mongoose. Below is what I have:
var accountSchema = new Schema({
firstName: String,
lastName: String,
email: String,
githubId: String,
githubAccessToken: String
});
passport.use(new GitHubStrategy({
clientID: config.GITHUB_CLIENT_ID,
clientSecret: config.GITHUB_CLIENT_SECRET,
callbackURL: "http://127.0.0.1/auth/github/callback",
scope: ['user', 'public_repo', 'repo', 'gist']
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate(...) // User is not defined
});
}));
How do I save a user to mongodb so they don't have to authenticate each time they visit the site? The example on the passport-github doesn't save anything to a database, which is what I'm looking to do? Are there any tutorials regarding this?
this could help: How to deal with async. findOrCreate method for passport and mongoose
basically you have to define a function (in your case that would be the findOrCreate function) that handles the database operation(s) and knows about the necessary mongoose schemas and models.