Practical hapi by Kanika Sud

Practical hapi by Kanika Sud

Author:Kanika Sud
Language: eng
Format: epub
ISBN: 9781484258057
Publisher: Apress


4. const validate = async (request, username, password) => {

const user = users[username];

if (!user) {

return { credentials: null, isValid: false };

}

const isValid = (password === user.password)?true:false;

const credentials = { id: user.id, name: user.name };

return { isValid, credentials };

};

5. const start = async () => {

const server = Hapi.server({ port: 4000 });

await server.register(require('@hapi/basic'));

server.auth.strategy('simple', 'basic', { validate });

server.route({

method: 'GET',

path: '/',

options: {

auth: 'simple'

},

handler: function (request, h) {

console.log(h);

return request.auth.credentials; }

});



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.