Move getToken method to utils

This commit is contained in:
Emil Ajdyna
2016-03-31 21:26:09 +02:00
parent 5ebdc028e4
commit c428135fbc
2 changed files with 17 additions and 17 deletions
+1 -17
View File
@@ -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)
+16
View File
@@ -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
}