auth.js
544 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// # auth
var passport = require('passport')
var lib, app
module.exports = function(_lib, _app) {
lib = _lib
app = _app
return auth
}
function auth() {
app.use(passport.initialize())
app.use(passport.session())
passport.serializeUser(serializeUser)
passport.deserializeUser(deserializeUser)
// TODO: add your passport auth here
}
function serializeUser(user, done) {
done(null, user.id)
}
function deserializeUser(id, done) {
lib.db.model('User').findById(id, function(err, user) {
done(err, user)
})
}