How to redirect after login?

I want to set up Lucee such that a logged-out user is redirected to the page they originally desired, as opposed to just the site homepage. I searched the documentation, but couldn’t figure it out.

How does one do this?

You need to capture that URL somehow. The easiest way is in the Session scope, e.g.

Session.gotoAfterLogin = "/path-where-user-wants-to-go-to";

If that is running in the target script itself, or in onRequestStart() for example, then you can do it like this:

Session.gotoAfterLogin = CGI.SCRIPT_NAME;

Then after a successful login you can use cflocation, e.g.

<cflocation url="#Session.gotoAfterLogin#">
2 Likes