'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'email', docs: { get: { description: 'verifies confirmation email', notes: 'Verifies the email from the stored hash', }, }, } module.exports = { method: 'GET', path: '/verify/{hash}', options: { ...pluginConfig.docs.get, tags: ['api'], auth: false, cors: true, handler: async function (request, h) { const { userService } = request.server.services() const hashToMatch = await userService.hashedEmail const hash = request.params.hash const hashesMatch = hashToMatch === hash ? true : false try { if (hashesMatch) { return { ok: true, handler: pluginConfig.handlerType, data: { hashesMatch: hashesMatch }, } } } 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('verify_email_res'), failAction: 'log', }, }, }