Skip to content

Instantly share code, notes, and snippets.

@GuillaumeBiton
Last active August 29, 2015 14:10
Show Gist options
  • Save GuillaumeBiton/43c1d2897447ca3c7751 to your computer and use it in GitHub Desktop.
Save GuillaumeBiton/43c1d2897447ca3c7751 to your computer and use it in GitHub Desktop.
var Hapi = require('hapi'),
server = new Hapi.Server();
server.connection();
var users = {
john: {
username: 'john',
password: 'john',
name: 'John Doe',
id: 1
}
};
var validate = function (username, password, callback) {
var user = users[username];
if (!user) {
return callback(null, false);
}
if (user.password === password) {
callback(false, true, { id: user.id, name: user.name});
}
};
server.register(require('hapi-auth-basic'), function (err) {
server.auth.strategy('simple', 'basic', false, { validateFunc: validate });
});
server.start(function () {
console.log(server.info);
});
server.route({
method: 'GET',
path: '/',
config: {
auth: 'simple'
},
handler: function (request, reply) {
return reply('Hello World');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment