mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-21 16:52:03 -07:00
Add passport
This commit is contained in:
+4
-2
@@ -5,10 +5,12 @@ const config = {
|
|||||||
port: process.env.PORT || 5000
|
port: process.env.PORT || 5000
|
||||||
},
|
},
|
||||||
development: {
|
development: {
|
||||||
session: 'secret-boilerplate-token'
|
session: 'secret-boilerplate-token',
|
||||||
|
database: 'mongodb://localhost:27017/koa2-boilerplate'
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
session: 'secret-boilerplate-token'
|
session: 'secret-boilerplate-token',
|
||||||
|
database: 'mongodb://localhost:27017/koa2-boilerplate'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import passport from 'koa-passport';
|
||||||
|
import User from '../src/models/users'
|
||||||
|
import { Strategy } from 'passport-local'
|
||||||
|
|
||||||
|
passport.serializeUser((user, done) => {
|
||||||
|
done(null, user.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
passport.deserializeUser(async (id, done) => {
|
||||||
|
try {
|
||||||
|
const user = await User.findById(id)
|
||||||
|
done(null, user)
|
||||||
|
} catch(err) {
|
||||||
|
done(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
passport.use('local', new Strategy({
|
||||||
|
usernameField: 'username',
|
||||||
|
passwordField: 'password'
|
||||||
|
}, async (email, password, done) => {
|
||||||
|
try {
|
||||||
|
const user = await User.findOne({ email, password })
|
||||||
|
if(!user) { return done(null, false) }
|
||||||
|
|
||||||
|
done(null, user)
|
||||||
|
} catch(err) {
|
||||||
|
return done(err)
|
||||||
|
}
|
||||||
|
}))
|
||||||
Reference in New Issue
Block a user