Handle authoring of pages on Author Instance | Community
Skip to main content
iamnjain
Community Advisor
Community Advisor
January 3, 2024
Solved

Handle authoring of pages on Author Instance

  • January 3, 2024
  • 2 replies
  • 719 views

Hello,

We are in a situation and maybe it's a common problem in AEM Project.

 

So we have specific pages which require user login to be accessed such as payment-summary, wishlist etc.
The project is AEM SPA and this condition is written on React components, to redirect to login if user is not logged in when try to access these protected pages.

 

Now, same code is available on Author instance pages as well and it's making a redirection and unable to author the page.

How to resolve this issue and Author should be able to author the component on Author instance?

 

 

@kautuk_sahni @arunpatidar @aanchal-sikka 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Madhur-Madan

Hi @iamnjain ,

If my understanding is correct. You need to bypass the login redirection on the author instance and implement on the publish instance. 
Maybe you can try to implement the logic on react side using any approach mentioned. 
1. Conditional Redirects : 

// Check if the environment is Author or Publish const isAuthorEnvironment = window.location.hostname.includes('author-instance'); // Redirect only if not logged in and in the Publish environment if (!isAuthorEnvironment && !isLoggedIn()) { window.location.href = '/login'; // Redirect to login page }

 

2. Excluding Redirects in Author Mode:

// Assuming a flag or environment variable distinguishes Author and Publish const isAuthorEnvironment = process.env.NODE_ENV === 'development'; if (!isAuthorEnvironment && !isLoggedIn()) { window.location.href = '/login'; // Redirect only in the Publish environment }

2 replies

Madhur-Madan
Community Advisor
Madhur-MadanCommunity AdvisorAccepted solution
Community Advisor
January 3, 2024

Hi @iamnjain ,

If my understanding is correct. You need to bypass the login redirection on the author instance and implement on the publish instance. 
Maybe you can try to implement the logic on react side using any approach mentioned. 
1. Conditional Redirects : 

// Check if the environment is Author or Publish const isAuthorEnvironment = window.location.hostname.includes('author-instance'); // Redirect only if not logged in and in the Publish environment if (!isAuthorEnvironment && !isLoggedIn()) { window.location.href = '/login'; // Redirect to login page }

 

2. Excluding Redirects in Author Mode:

// Assuming a flag or environment variable distinguishes Author and Publish const isAuthorEnvironment = process.env.NODE_ENV === 'development'; if (!isAuthorEnvironment && !isLoggedIn()) { window.location.href = '/login'; // Redirect only in the Publish environment }
arunpatidar
Community Advisor
Community Advisor
January 3, 2024

Hi @iamnjain 
You can add a class in your page if you are on author mode

 

<sly data-sly-test.isAuthorMode="${wcmmode.edit || wcmmode.design}"/> <div class="c-ac-container__default-parsys ${isAuthorMode ? 'author-page' : ''}"> ....

 
or you can use wcmmode cookies to identify if this is author instance or publish

Arun Patidar
iamnjain
Community Advisor
iamnjainCommunity AdvisorAuthor
Community Advisor
January 5, 2024

@arunpatidar 

The first suggestion I thought about it. But, since this is AEM SPA, we don't have HTL files for components, everything is controlled at FE component.

In your second suggestion, I checked the browser cookie, we have wcmmode=edit. This might work. Let me try with this.

I will update here.