mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-21 16:52:03 -07:00
Moved middleware to middleware directory
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export function errorMiddleware() {
|
||||
return async (ctx, next) => {
|
||||
try {
|
||||
await next()
|
||||
} catch (err) {
|
||||
ctx.status = err.status || 500
|
||||
ctx.body = err.message
|
||||
ctx.app.emit('error', err, ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import User from '../models/users'
|
||||
import config from '../../config/config'
|
||||
import { verify } from 'jsonwebtoken'
|
||||
|
||||
export async function ensureUser(ctx, next) {
|
||||
const { token } = ctx.query
|
||||
|
||||
if (!token) {
|
||||
ctx.throw(401)
|
||||
}
|
||||
|
||||
let decoded = null
|
||||
try {
|
||||
decoded = verify(token, config.tokenSecret)
|
||||
} catch (err) {
|
||||
ctx.throw(401)
|
||||
}
|
||||
|
||||
const user = await User.findById(decoded.id, '-password -salt')
|
||||
if (!user) {
|
||||
ctx.throw(401)
|
||||
}
|
||||
|
||||
return next()
|
||||
}
|
||||
Reference in New Issue
Block a user