On click of the link if the user is not logged in it will take them to the login page where they log in first.
Once they login they are redirected the url specified above.
The bit I am unsure off is if I the security manager directs them to login and they login how do I cache the link they clicked so they are then redirected to the specified url?
Let me know if the process or question is not clear!
Since you are using NodeJS, you can make use of the server side server connect to handle this.
If you are already using a Server Action for this, you can modify it. If not, just create a new SA.
In the SA for server side server connect, check that if there is a ID in $_PARAM. If it does, save the current URL ($_SERVER.PATH_INFO) in a session variable.
Then, your page level security enforcer redirects the user to login page.
After the security login step, your login SA would check if the redirect session exists. If it does do a set value with that URL & delete session. Else, do a set value with your regular homepage URL.
On client side, in login server connect on:success event, do a browser goto to whatever the returned URL is.