controllers/auth.js   A
last analyzed

Size

Lines of Code 46

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
nc 1
dl 0
loc 46
rs 10
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B auth.js ➔ ??? 0 39 1
1
var Router = require('express')
2
var passport = require('passport')
3
const passportConfig = require('../config/passport')
0 ignored issues
show
Unused Code introduced by
The constant passportConfig seems to be never used. Consider removing it.
Loading history...
4
5
module.exports = class AuthController {
6
7
  route () {
8
    const router = new Router()
9
        // GET /auth/google
10
        //   Use passport.authenticate() as route middleware to authenticate the
11
        //   request.  The first step in Google authentication will involve
12
        //   redirecting the user to google.com.  After authorization, Google
13
        //   will redirect the user back to this application at /auth/google/callback
14
    router.get('/google', passport.authenticate('google', {
15
      scope: [
16
        'https://www.googleapis.com/auth/plus.login',
17
        'https://www.googleapis.com/auth/plus.profile.emails.read']
18
    }))
19
20
        // GET /auth/google/callback
21
        //   Use passport.authenticate() as route middleware to authenticate the
22
        //   request.  If authentication fails, the user will be redirected back to the
23
        //   login page.  Otherwise, the primary route function function will be called,
24
        //   which, in this example, will redirect the user to the home page.
25
    router.get('/google/callback',
26
            passport.authenticate('google', {
27
              successRedirect: '/auth/account',
28
              failureRedirect: '/auth/login'
29
            }))
30
31
    router.get('/account', passportConfig.ensureAuthenticated, function (req, res) {
0 ignored issues
show
Bug introduced by
The variable passportConfig seems to be never declared. If this is a global, consider adding a /** global: passportConfig */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
      res.render('account', { user: req.user })
33
    })
34
35
    router.get('/login', function (req, res) {
36
      res.render('login', { user: req.user })
37
    })
38
39
    router.get('/logout', function (req, res) {
40
      req.logout()
41
      res.redirect('/')
42
    })
43
44
    return router
45
  }
46
}
47