0

i am trying to create an oauth for a website. no collections have been created in the mongodb. this is my function to write data:

User.findOne({googleId: profile.id}).then((currentUser) => {

        if(currentUser){
            // already have this user
            console.log('user is: ', currentUser);
            done(null, currentUser);
        } else {
            console.log('DEBUG Login');
            // if not, create user in our db
            new User({
                googleId: profile.id,
                username: profile.displayName,
                thumbnail: profile._json.image.url
            }).save().then((newUser) => {
                console.log('created new user: ', newUser);
                done(null, newUser);
            });
        }
    });

This is my user-model:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const userSchema = new Schema({
    username: String,
    googleId: String,
    thumbnail: String
});

const User = mongoose.model('user', userSchema);

module.exports = User;
Shivam
  • 3,514
  • 2
  • 13
  • 27

0 Answers0