summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoHong Li2017-04-12 06:07:19 +0800
committerRaccoon Li2017-05-08 19:29:06 +0800
commitd88502e3315f189af28ac6e86fccfa1406d75b52 (patch)
tree7f806f7e710a354a45ebaa0e7bfbb41b0feae2b9
parent7ef17fd4e61503178875dd34f998203264ffb691 (diff)
refactor(app.js): Move passport serialize and deserialize to auth module
Diffstat (limited to '')
-rw-r--r--app.js19
-rw-r--r--lib/web/auth/index.js22
2 files changed, 22 insertions, 19 deletions
diff --git a/app.js b/app.js
index 3cfa2a18..1d0d9862 100644
--- a/app.js
+++ b/app.js
@@ -154,25 +154,6 @@ app.use(flash())
app.use(passport.initialize())
app.use(passport.session())
-// serialize and deserialize
-passport.serializeUser(function (user, done) {
- logger.info('serializeUser: ' + user.id)
- return done(null, user.id)
-})
-passport.deserializeUser(function (id, done) {
- models.User.findOne({
- where: {
- id: id
- }
- }).then(function (user) {
- logger.info('deserializeUser: ' + user.id)
- return done(null, user)
- }).catch(function (err) {
- logger.error(err)
- return done(err, null)
- })
-})
-
// check uri is valid before going further
app.use(require('./lib/web/middleware/checkURiValid'))
diff --git a/lib/web/auth/index.js b/lib/web/auth/index.js
index 3a203800..18d70572 100644
--- a/lib/web/auth/index.js
+++ b/lib/web/auth/index.js
@@ -1,12 +1,34 @@
'use strict'
const Router = require('express').Router
+const passport = require('passport')
const config = require('../../config')
const logger = require('../../logger')
+const models = require('../../models')
const authRouter = module.exports = Router()
+// serialize and deserialize
+passport.serializeUser(function (user, done) {
+ logger.info('serializeUser: ' + user.id)
+ return done(null, user.id)
+})
+
+passport.deserializeUser(function (id, done) {
+ models.User.findOne({
+ where: {
+ id: id
+ }
+ }).then(function (user) {
+ logger.info('deserializeUser: ' + user.id)
+ return done(null, user)
+ }).catch(function (err) {
+ logger.error(err)
+ return done(err, null)
+ })
+})
+
if (config.facebook) authRouter.use('/', require('./facebook'))
if (config.twitter) authRouter.use('/', require('./twitter'))
if (config.github) authRouter.use('/', require('./github'))