Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- /**
- * Route definition for authentication/authorization endpoints.
- * @author Challenge.IT
- */
- const Boom = require('boom')
- const Joi = require('joi')
- module.exports = (server, opts) => {
- /*
- Command example:
- $ curl -i -H 'Content-Type: application/json' -d '{"username": "rikmms", "password": "admin"}' http://localhost:3000/login
- */
- server.route({
- method: 'POST',
- path: '/login',
- handler: function(request, reply) {
- opts.customProvider.login(request.payload.username, request.payload.password, (err, user) => {
- reply(err? (err.code? Boom.badRequest(err.message) : err) : null, {user: user})
- })
- },
- config: {
- auth: false,
- validate: {
- payload: {
- username: Joi.string().required(),
- password: Joi.string().required()
- }
- }
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement