Everyauth: github authentication for database

I am new to node.js and I have a problem with the allAuth module.

My problem: I am trying to create an application that allows the user to log in through github oauth and checks if the user is included in the database. I want authentication to return until I verify that the user is in the white list. I tried several ways to do this, but to no avail.

Can anyone shed some light?

Github method call

everyauth.github .appId(conf.github.appId) .appSecret(conf.github.appSecret) .redirectPath('/') .findOrCreateUser (sess, accessToken, accessTokenExtra, ghUser) -> promise = this.Promise() users.findOrCreateByGhData ghUser, accessToken, accessTokenExtra, promise promise; 

User class

 conf = require '../config' # Mongoose mongoose = require 'mongoose' Schema = mongoose.Schema ObjectId = Schema.ObjectId # Connect mongoose.connect('mongodb://' + conf.db.user + ':' + conf.db.password + '@' + conf.db.url ) # User Schema NewUser = new Schema id : type: Number min: 18 index: true login : type: String ghId : type: Number unique: true date : type: Date default: Date.now # Create Model User = mongoose.model 'NewUser', NewUser exports.findOrCreateByGhData = ( ghData , accessToken, accessTokenExtra, promise ) -> User.find 'ghId': ghData.id , (err, docs) -> if docs.length console.log '=========User===============' console.log docs return promise.fulfill ['Nah its an error'] else console.log '=========No user=============' user = new User() user.login = ghData.login user.ghId = ghData.id user.save ( err ) -> if err throw err console.log 'saved' promise.fulfill user 
+4
source share
2 answers

I had some problems with Everyauth at the beginning, so I switched to Passport . There is a module for GitHub authentication . In my opinion, it is much easier to use. The passport provides a user profile that you can simply save to the database and retrieve after successful authentication.

+1
source

promise.fail what are you blocking for?

 function (session, accessToken, extra, user) { var promise = this.Promise(); doSomethingAsync(function (err, user) { if (user.whitelisted) promise.fulfill(user); else promise.fail('denied'); }); return promise; } 
0
source

Source: https://habr.com/ru/post/1381225/


All Articles