'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'email', docs: { get: { description: 'gets jwt after verifying email', notes: 'Gets jwt after validating email', }, }, } module.exports = { method: 'POST', path: '/getjwt', options: { ...pluginConfig.docs.get, tags: ['api'], auth: false, cors: true, handler: async function (request, h) { const { userService } = request.server.services() const res = request.payload const token = await userService.createToken(res) // TODO: Move logic adding initial three responses to here try { // return h.state(token) return { ok: true, handler: pluginConfig.handlerType, data: token, } } 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.string(), }).label('get_jwt_res'), failAction: 'log', }, }, }