node.js


Add custom login form to hapi-auth-basic


I use hapi-auth-basic to authenticate users. My question is how to add custom login form instead of using the basic form of the browser.
You can bind the functionality of hapi-auth-basic to any custom login form. You need to make sure that the properties get evaluated correctly on server side.
Here's a dedicated tutorial on basic authentication in hapi with hapi-auth-basic.
Let's say you've a form like this: (it's very simple for illustration purposes)
<form action="/login" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" value="Log in">
</form>
On server side, you need to have multiple things in place:
an authentication strategy with a validateFunc that takes the input and evaluates it against your data set (like database)
a route handler for method POST on path /login, because the form sends the data to this endpoint
the auth config set with your strategy at the route handler
What I mean is a setup like this: (again, simplified)
server.auth.strategy('simple', 'basic', { validateFunc: (request, username, password, callback) => {} })
server.route({
method: 'GET',
path: '/private-route',
config: {
auth: 'simple',
handler: function (request, reply) {
reply('Yeah! This message is only available for authenticated users!')
}
}
})
Hope that helps!

Related Links

How to add img src attribute with VueJs
get request is not working after changing html5Mode(true). Need an help in express node.js
Node.js google drive api - authorize without consent screen
How to select deep nested data in mongodb using mongoose in nodejs
SyntaxError: Unexpected token )
Creating service for nodejs app in Oracle linux
How to install only “build” or “dist” or output result of a library via npm
A Dummy's guide Offline install of NPM Packages Windows
How to get read headers in node.js using body-parser?
horizon js can not access rethinkdb in port 28025 without --dev flag . Error : action not permitted
Nodejs - Passport - Failed to serialize user into session
How to access uploaded file from multer?
how to compare column of other table in join sequelize
Which model to put certain fields for a MongoDb schema
NodeJS: How do I enable CHACHA20_POLY1305 in https?
Change the default content of a site if the site is redirected

Categories

HOME
hyper-v
github
veins
analytics
servicestack
webserver
google-home
jboss-eap-6
acr122
pygtk
crc32
shoutem
treeset
log4net
salt-stack
twitter-typeahead
clang-format
selenium-rc
bootstrap-select
unimrcp
xbuild
robotium-recorder
mahapps.metro
heatmap
spring-4
drools-fusion
live
dexguard
sqlcmd
dataweave
shieldui
qnx
carplay
inputstreamreader
erpnext
zoo
android-7.1-nougat
apple-search-ads
erwin
audio-player
rate
deferred-loading
apple-watch-complication
eclipse-indigo
devpartner
onbeforeunload
giflib
rodbc
mediafire
phpinfo
eclipse-emf-ecore
youtube-javascript-api
fody-propertychanged
delphi-5
bullseye
offsetheight
mpi4py
eofexception
c1flexgrid
er-diagrams
xcode-organizer
stackato
option
deface
zurb-joyride
n-tier
telerik-test-studio
socketrocket
inter-process-communicat
nsfontmanager
node-http-proxy
delphiscript
circular-reference
mdbtools
slimv
wexitstatus
icefaces-1.8
ubuntu-9.10
mindmapping
clean-language

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile