'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'jwt', docs: { get: { description: 'validates jwt for each step of survey', notes: 'validates jwt for each step of survey', }, }, } module.exports = { method: 'GET', path: '/validatejwt/{jwt}', options: { ...pluginConfig.docs.get, tags: ['api'], auth: false, cors: true, handler: async function (request, h) { const jwt = request.params.jwt const { userService } = request.server.services() const jwtIsValid = userService.validateToken(jwt) try { return { ok: true, handler: pluginConfig.handlerType, data: { isValid: jwtIsValid.isValid, payload: jwtIsValid.payload, }, } } catch (err) { return { ok: false, handler: pluginConfig.handlerType, data: { error: err, }, } } }, validate: { failAction: 'log', }, response: { schema: Joi.object({ ok: Joi.bool(), handler: Joi.string(), data: Joi.object(), }).label('validate_jwt_res'), failAction: 'log', }, }, }