diff options
| author | Adam Soltys <[email protected]> | 2018-03-02 16:46:49 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2018-03-02 16:46:49 -0800 |
| commit | da49c83d765e88fb505bcfc76e6f41763f5ceedd (patch) | |
| tree | 49898b3bf5f5cef11ab82a32b9a260b75448e95a /passport.js | |
| parent | 9e69c2f3f6ca8c65d9ad1146121b56f5e6194e6e (diff) | |
| download | coinos-server-da49c83d765e88fb505bcfc76e6f41763f5ceedd.tar.gz coinos-server-da49c83d765e88fb505bcfc76e6f41763f5ceedd.zip | |
authenticate sockets and only emit to specific subscribers
Diffstat (limited to 'passport.js')
| -rw-r--r-- | passport.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/passport.js b/passport.js index ac34178f..7456532a 100644 --- a/passport.js +++ b/passport.js @@ -3,16 +3,19 @@ import jwt from 'passport-jwt' import dotenv from 'dotenv' dotenv.config() +const l = console.log + function cookieExtractor (req) { if (req && req.cookies) return req.cookies['token'] return null } module.exports = (db) => { - passport.use(new jwt.Strategy({ + passport.use( + new jwt.Strategy({ jwtFromRequest: jwt.ExtractJwt.fromExtractors([cookieExtractor]), secretOrKey: process.env.SECRET - }, async function (payload, next) { + }, async (payload, next) => { try { let user = await db.User.findOne({ where: { @@ -21,6 +24,7 @@ module.exports = (db) => { }) next(null, user) } catch(err) { + l(err) next(null, false) } }) @@ -29,3 +33,4 @@ module.exports = (db) => { return passport } + |
