Redirect to Content Page With Different Layout Does Not Work For SPA

I have a server side server action setup on a content page - which is used as security restrict.
This content page - page1 - has layout page - layout1.
My login page - login1 - has a different layout page - layout2.

Post login, I get redirected to a secure page, which is ok.
Now, when I click some link with internal redirection (anchor or browser), the content page page1 is not accessible to the logged in user, so they should get redirected to login page.
For this, my server side server action has a redirect step.
But at this point, rather than loading the layout2 with login1, login1 gets loaded inside layout1.

From the web server logs, what I could understand is that the internal redirection was requesting a “template”, and when the redirect step was encountered, it just returned the login1 content page, instead of both layout and content.

If this is an expected behaviour, how do I redirect user to login page?
Maybe a checkbox to do “non-internal” redirection could work?
Please help.

Community Page
Last updated: