18 lines
486 B
JavaScript
18 lines
486 B
JavaScript
import { HttpError } from '../error.mjs'
|
|
import decode from '../jwt/decode.mjs'
|
|
import config from '../config.mjs'
|
|
|
|
export function verifyToken(ctx) {
|
|
let token = ctx.query.get('token')
|
|
if (!token) {
|
|
throw new HttpError('Token is missing in query', 422)
|
|
}
|
|
|
|
try {
|
|
let decoded = decode(token, config.get('sites'), [])
|
|
return decoded.iss
|
|
} catch (err) {
|
|
ctx.log.error(err, 'Error decoding token: ' + token)
|
|
throw new HttpError('Token was invalid', 422)
|
|
}
|
|
}
|