"redirectOnTry" make me confused
Closed this issue · 2 comments
Hi,
The doc said:
redirectOnTry - if false and route authentication mode is 'try', authentication errors will not trigger a redirection. Requires hapi version 6.2.0 or newer.
I wrote an example and the part of route like this:
server.route({
method: 'GET',
path: '/',
config: {
auth: {
mode: 'try',
strategy: 'session'
},
plugins: {
'hapi-auth-cookie': {
redirectOnTry: false,
redirectTo: false // If remove this, the route will be always redirected.
}
},
handler: function(request, reply) {
reply('This is index page.');
}
}
})
Please see the comment in the code.
I am new to hapi.js and it's hard to find relevant references with google. I am not sure what exactly this is a bug, just hope someone can guide me. Thanks!
Below is the full code of my example:
BTW: I am using hapi.js v16.4.3
const Hapi = require('hapi')
const CookieAuth = require('hapi-auth-cookie')
const server = new Hapi.Server()
server.connection({
host: 'localhost',
port: 3000
})
// register plugins to server instance
server.register(CookieAuth, function(err) {
if (err) {
throw err
}
server.auth.strategy('session', 'cookie', true, {
password: 'm!*"2/),p4:xDs%KEgVr7;e#85Ah^WYC',
cookie: 'tutorials-cookie-auth-example',
redirectTo: '/',
isSecure: false,
validateFunc: function(request, session, callback) {
var username = session.username
var user = Users[username]
if (!user) {
return callback(null, false)
}
callback(err, true, user)
}
})
server.route({
method: 'GET',
path: '/',
config: {
auth: {
mode: 'try',
strategy: 'session'
},
plugins: {
'hapi-auth-cookie': {
redirectOnTry: false,
redirectTo: false // If remove this, the route will be always redirected.
}
},
handler: function(request, reply) {
reply('This is index page.');
}
}
})
})
server.start()
I understand now, the "redirectOnTry" should be set in "server.auth.strategy", not in individual route. Sorry to bother you!
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.