How to add simple passport or basic auth to hapi
I need help trying to create a simple application that will display a public login page and, after authenticating, will be redirected to the index.html page ..
I thought it should be pretty straight forward, took the first step, but adding the Auth / Passport plugin and redirects doesn't work.
Below is an example https://github.com/makrand-bkar/hapi-simple-auth-tutorial
Any help is much appreciated, kinda stuck here
Poppy
source to share
What you are looking for is the hapi auth tutorial: http://hapijs.com/tutorials/auth
I've forked the github repository to see what you are doing, but it looks like you don't have any auth related code preinstalled right now. Essentially, you need to do the following:
- Create a logon view that stores users on a database system such as Postgres or MongoDB.
- User password hash.
- Get customization using CSRF to prevent spoofing requests from different sites.
- Create a login box that validates the database for a user / password hash to validate credentials.
- Use a session system (for example with cookies) to save user state.
- Create helpers to load users from cookies.
- Write support materials to validate users before allowing access to protected pages.
Now it is obviously very annoying to write the whole thing yourself.
Fortunately, hapi has plugins that help with this, namely: https://github.com/Mkoopajr/hapi-session-mongo
Hope it helps!
source to share