Warm tip: This article is reproduced from serverfault.com, please click

Branch on Log In Page (APEX 19.2)

发布于 2020-12-02 13:16:09

I have an application that has two pages:

  • Page 1: Home Page where Authentication: Page is Public
  • Page 2: Authentication: Page Requires Authentication

If a visitor is not authenticated, then the application should go to Page 1. If visitor logs in and is authenticated, then the application should redirect user to Page 2 after logging in.

ATTEMPT 1: I tried putting a branch (tried both Processing and After Process points) on Page 9999 (Login Page) that would redirect to Page 2. I was not able to get this to work.

ATTEMPT 2: I moved the branch to the Before Header of Page 1 with a server-side condition to branch check if user is authenticated. This worked.

My question is why did my first attempt not work? Maybe it is my way of thinking, but I would think either method should work. I prefer to have it on the Login Page as I know this redirect should ALWAYS happen after logging in, and it is more true to the flow that I am after. I'm sure I'm missing something obvious as I am only a few weeks in to learning APEX.

I ended up using the suggestion here (using a router page) as it logically makes sense to me and is more self-documenting, but more curious why my method 1 didn't work.

Thanks in advance for any help.

Questioner
McRivers
Viewed
0
Koen Lostrie 2020-12-03 00:05:19

In most cases, authentication is done outside of the application (SAML/SSO/...) - using apex accounts for authentication is not often done in production environments. It is best to split the authentication from the application altogether. If you start adding business logic to a login page you're going against that practice. Personally I think it is also overkill to display a login page to a user that doesn't have to authenticate. So far about why you made the correct choice.

Now why it failed. The documentation of apex_authentication.login shows that a "redirect" is the last step of the authentication process. If authentication passes then a user is redirected to the application home page, if it fails he is redirected to the page that is defined in the Shared Components > Authentication schemes > Current authentication scheme > Session not valid attribute. If you run debug on the login page that is the behaviour you can observe. My guess is that redirect will run before your own branch which is why it didn't work for you. It probably is expected behaviour.