mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Move auth controllers to new modules
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import passport from 'koa-passport'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import config from '../../config'
|
||||
|
||||
export async function authUser(ctx, next) {
|
||||
return passport.authenticate('local', (user) => {
|
||||
if (!user) {
|
||||
ctx.throw(401)
|
||||
}
|
||||
|
||||
const token = jwt.sign({ id: user.id }, config.token)
|
||||
|
||||
const response = user.toJSON()
|
||||
|
||||
delete response.password
|
||||
delete response.salt
|
||||
|
||||
ctx.body = {
|
||||
token,
|
||||
user: response
|
||||
}
|
||||
})(ctx, next)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import * as auth from './controller'
|
||||
|
||||
export default {
|
||||
base: '/auth',
|
||||
|
||||
'Authenticate user': {
|
||||
method: 'POST',
|
||||
route: '/',
|
||||
handlers: [
|
||||
auth.authUser
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user