mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-21 16:52:03 -07:00
Move getToken method to utils
This commit is contained in:
@@ -1,24 +1,8 @@
|
||||
import User from '../models/users'
|
||||
import config from '../../config'
|
||||
import { getToken } from '../utils/auth'
|
||||
import { verify } from 'jsonwebtoken'
|
||||
|
||||
function getToken(ctx) {
|
||||
const header = ctx.request.header.authorization
|
||||
if (!header) {
|
||||
return null
|
||||
}
|
||||
const parts = header.split(' ')
|
||||
if (parts.length !== 2) {
|
||||
return null
|
||||
}
|
||||
const scheme = parts[0]
|
||||
const token = parts[1]
|
||||
if (/^Bearer$/i.test(scheme)) {
|
||||
return token
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export async function ensureUser(ctx, next) {
|
||||
const token = getToken(ctx)
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
export function getToken(ctx) {
|
||||
const header = ctx.request.header.authorization
|
||||
if (!header) {
|
||||
return null
|
||||
}
|
||||
const parts = header.split(' ')
|
||||
if (parts.length !== 2) {
|
||||
return null
|
||||
}
|
||||
const scheme = parts[0]
|
||||
const token = parts[1]
|
||||
if (/^Bearer$/i.test(scheme)) {
|
||||
return token
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user