in reply to Dancer sessions and before hook

This regex:

m{^/login|/}

will match anything starting with /login, OR anything containing a forward slash. So it'll match all your routes, and the second half of your if condition will never be true, and your before hook will never redirect to /login.

If you're trying to match either the /login page OR the home page, you'll need to anchor that part of the pattern, or compare strings directly instead of a regex:

m{^/login|^/$}; # or if($route ne '/login' and $route ne '/'){

Aaron B.
Available for small or large Perl jobs; see my home node.

Replies are listed 'Best First'.
Re^2: Dancer sessions and before hook
by monktopher (Novice) on Jul 28, 2012 at 04:14 UTC

    Aaron

    Thank you for your reply. That fixed the issue.

    I had to type out that if statement in English to fully understand what was going wrong:If the user does not have a session AND they're trying to get to someplace other than /login or /, redirect them to /login. Since my regex was matching anything starting with /, there was no other place where they could go, making the 2nd half fail like you said.