aboutsummaryrefslogtreecommitdiffstats
path: root/passport.js
diff options
context:
space:
mode:
Diffstat (limited to 'passport.js')
-rw-r--r--passport.js60
1 files changed, 32 insertions, 28 deletions
diff --git a/passport.js b/passport.js
index 246dfba8..1fc4a4d9 100644
--- a/passport.js
+++ b/passport.js
@@ -1,35 +1,39 @@
-import passport from 'passport'
-import jwt from 'passport-jwt'
-import config from './config'
+const passport = require("passport");
+const jwt = require("passport-jwt");
+const config = require("./config");
-const l = console.log
+const l = console.log;
-function cookieExtractor (req) {
- if (req && req.cookies) return req.cookies['token']
- return null
+function cookieExtractor(req) {
+ if (req && req.cookies) return req.cookies["token"];
+ return null;
}
-module.exports = (db) => {
+module.exports = db => {
passport.use(
- new jwt.Strategy({
- jwtFromRequest: jwt.ExtractJwt.fromExtractors([jwt.ExtractJwt.fromAuthHeaderAsBearerToken(), cookieExtractor]),
- secretOrKey: config.jwt
- }, async (payload, next) => {
- try {
- let user = await db.User.findOne({
- where: {
- username: payload.username
- }
- })
- next(null, user)
- } catch(err) {
- l(err)
- next(null, { username: 'guest' })
+ new jwt.Strategy(
+ {
+ jwtFromRequest: jwt.ExtractJwt.fromExtractors([
+ jwt.ExtractJwt.fromAuthHeaderAsBearerToken(),
+ cookieExtractor
+ ]),
+ secretOrKey: config.jwt
+ },
+ async (payload, next) => {
+ try {
+ let user = await db.User.findOne({
+ where: {
+ username: payload.username
+ }
+ });
+ next(null, user);
+ } catch (err) {
+ l(err);
+ next(null, { username: "guest" });
+ }
}
- })
- )
-
- return passport
-}
-
+ )
+ );
+ return passport;
+};