You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

authentication.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict'
  2. const Joi = require('joi')
  3. const params = require('../../schemas/params')
  4. const pluginConfig = {
  5. handlerType: 'password',
  6. docs: {
  7. get: {
  8. description: 'get password',
  9. notes: 'Returns a password by the user email passed in the path',
  10. },
  11. },
  12. opts: {
  13. tags: ['api'],
  14. auth:
  15. process.env.USE_AUTH != 'true'
  16. ? false
  17. : { strategy: 'default_jwt' },
  18. cors: true,
  19. },
  20. }
  21. /** Validator functions by request method */
  22. const validators = {
  23. /** Validate the route params (/active/{thing}) */
  24. params: params.userEmail,
  25. }
  26. module.exports = {
  27. method: 'GET',
  28. path: '/{user_email}/password',
  29. options: {
  30. ...pluginConfig.docs.get,
  31. ...pluginConfig.opts,
  32. handler: async function (request, h) {
  33. try {
  34. const { userService } = request.services()
  35. const userEmail = request.params.user_email
  36. const password = await userService.getPassword(userEmail)
  37. return {
  38. ok: true,
  39. handler: pluginConfig.handlerType,
  40. data: { password: password },
  41. }
  42. } catch (err) {
  43. return {
  44. ok: false,
  45. handler: pluginConfig.handlerType,
  46. data: { error: err },
  47. }
  48. }
  49. },
  50. validate: {
  51. ...validators,
  52. failAction: 'log',
  53. },
  54. response: {
  55. schema: Joi.object({
  56. ok: Joi.bool(),
  57. handler: Joi.string(),
  58. data: Joi.object(),
  59. }).label('password_res'),
  60. failAction: 'log',
  61. },
  62. },
  63. }