HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinorCanonical

node.js Passport Wrapper 3

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
nodewrapperpassport

Problem

First attempt was done here

Second attempt was done here
Huge comment at top

```
/*
* Export single function that creates the passportControl object
* The function has two parameters:
* app: The nodejs/express service object.
* This is used to register the end points
* this authentication object listens too.
* register: An object that abstracts user registrations it
* must support the following methods:
* updateUser({})
* getSavedUser(localUserId, function(err, localUser) {})
*
* It also uses an external module for configuration (ie holding all the secrets)
* This file is not in source control (but in a key repository nice and safe).
* config: Expected fields:
* config.app The URL of the site.
* config.passport An object containing the secrets for each service
* The values will depend on the service and the
* implementation of passport- module
* See the passport code for more detail
* Example:
*
{
app: 'iPubCrawlMaps.com',
short: 'iPCM',
passport: {
facebook: {
clientID: ''
clientSecret: ''
},
twitter: {
consumerKey: '',
consumerSecret: ''
},
google: {
returnURL: 'http:///api/auth/callback?type=google',
realm: 'http:///'
},

Solution

I think you're nailing it.

As a nitpick, the indentation is a bit off in the registerUser function definition.

Another tiny thing in the same function, instead of this:

function(err, localUser) {
    if (err) {done(err); return; }
    done(null, localUser);
}


How about the shorter:

function(err, localUser) {
    err ? done(err) : done(null, localUser);
}


Since the method is not supposed to return anything anyway, this will have the same effect as the original, but it's shorter and perhaps a tiny bit easier to read.

Code Snippets

function(err, localUser) {
    if (err) {done(err); return; }
    done(null, localUser);
}
function(err, localUser) {
    err ? done(err) : done(null, localUser);
}

Context

StackExchange Code Review Q#47392, answer score: 3

Revisions (0)

No revisions yet.