config/passport/google.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 38
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 38
rs 10
wmc 5
mnd 1
bc 5
fnc 3
bpm 1.6666
cpm 1.6666
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B google.js ➔ ??? 0 24 1
1
'use strict'
2
var mongoose = require('mongoose')
3
var GoogleStrategy = require('passport-google-oauth2').Strategy
4
var User = mongoose.model('User')
5
var config = require('../')
6
var logger = require('winston')
7
8
module.exports = new GoogleStrategy({
9
  clientID: config.google.clientId,
10
  clientSecret: config.google.clientSecret,
11
  callbackURL: config.baseUrl + config.google.callbackPath /* ,
12
  passReqToCallback: true */
13
},
14
  function (accessToken, refreshToken, profile, done) {
15
    const options = {
16
      criteria: { 'google.id': profile.id }
17
    }
18
    User.load(options, function (err, user) {
19
      if (err) return done(err)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
      if (!user) {
21
        user = new User({
22
          name: profile.displayName,
23
          email: profile.emails[0].value,
24
          username: profile.username,
25
          provider: 'google',
26
          google: profile._json
27
        })
28
        user.save(function (err) {
29
          logger.error('Error saving user: ' + err)
30
          return done(err, user)
31
        })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
32
      } else {
33
        logger.debug('Returning user : ' + user)
34
        return done(err, user)
35
      }
36
    })
37
  }
38
)
39