Now let’s assume that every page in our website is gated that means you need to login to the site with valid credentials to access any page of the site.
To do this you can follow the Sitecore blog.
Once you mark the website as required login and give the link of the Login page in the Site Grouping:

Update the Controller and Action in the Layout section of the Login Page:
Controller: Sitecore.XA.Feature.Security.Controllers.LoginPageController,Sitecore.XA.Feature.Security
Action: IndexForLogin

Now we will need to make small update in our logic for custom submit action we created in last blog.
In the previous blog, we had redirected the user to Home page upon valid credentials but since our website is gated, it will generate a return URL whenever any page is tired to access so we should redirect the user to the requested page.
Update the logic for redirection to Home page using below code:
//Redirect to the return URL
var url = Sitecore.Context.RawUrl;
if (!string.IsNullOrEmpty(url))
{
var variables = url.Split('&');
url = variables[0].Substring(23);
}
formSubmitContext.RedirectUrl = !string.IsNullOrEmpty(url) ? HttpUtility.UrlDecode(url) : "/";
formSubmitContext.RedirectOnSuccess = true;
Once the code is published, try to access the Sample Page and it will automatically redirect you to login page:

Upon entering valid credentials, the user will be redirected to the sample-page.

Hope it helps.. In the next part, we will see how we can integrate the Log out logic in the Simple Authentication series.
Thank you.. Happy Learning.. Happy Sitecoring.. 🙂