Restricting Storefront Access for Anonymous Customers
Hi Spryker community,
I'm currently working on configuring my Spryker storefront to restrict access for anonymous customers, redirecting them to the login page. I've come across a configuration for this purpose, but I'm facing some challenges in modifying the regex patterns.
The current configuration I'm using is as follows:$config[CustomerConstants::CUSTOMER_SECURED_PATTERN] = '(^/login_check$|^(/en|/de)?/customer($|/)|^(/en|/de)?/wishlist($|/)|^(/en|/de)?/shopping-list($|/)|^(/en|/de)?/quote-request($|/)|^(/en|/de)?/comment($|/)|^(/en|/de)?/company(?!/register)($|/)|^(/en|/de)?/multi-cart($|/)|^(/en|/de)?/shared-cart($|/)|^(/en|/de)?/cart(?!/add)($|/)|^(/en|/de)?/checkout($|/))';
$config[CustomerConstants::CUSTOMER_ANONYMOUS_PATTERN] = '^/.*';
I've attempted to modify the regex patterns to achieve the desired behavior, but unfortunately, it's not working as expected. Can anyone provide assistance or suggest an alternative approach to restrict storefront access for anonymous customers?
Your insights and guidance will be highly appreciated!
Thank you!
Best Answer
-
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)
Heyhey,
let's inverse it:leave the ANONYMOUS_PATTERN as default, but specify that everything except xyz is secured.
For example:
$config[CustomerConstants::CUSTOMER_SECURED_PATTERN] = '^(?!(/en|/de)?(/login$|/register.*|/error/.*|/password/.*|/robots.txt|/agent.*|/sales-agent/*|/imprint)).*';
I am happy to hear back from you if this works :)
All the best,
Florian
0
Answers
-
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)
Heyhey @bhupendra.doniwal ,
it's not working as expected
Can you please elaborate on this? What is not working as expected?
All the best,
Florian
0 -
For example
$config[CustomerConstants::CUSTOMER_ANONYMOUS_PATTERN] = '^/(?!login_check|login\/(en|de)$)';
it should access only the login page and login check but all the other pages are accessible like PDP PLP
or can you help me write the right regex?0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 ⚖️ - Guardians (admin)
Heyhey,
let's inverse it:leave the ANONYMOUS_PATTERN as default, but specify that everything except xyz is secured.
For example:
$config[CustomerConstants::CUSTOMER_SECURED_PATTERN] = '^(?!(/en|/de)?(/login$|/register.*|/error/.*|/password/.*|/robots.txt|/agent.*|/sales-agent/*|/imprint)).*';
I am happy to hear back from you if this works :)
All the best,
Florian
0 -
Hey Florian,
I wanted to let you know that I've implemented the suggested configuration, and it's working like a charm! Your advice was incredibly helpful, and I appreciate your quick response.
If you have any further insights or tips, feel free to share. Thanks again for your assistance!
Best regards,
Bhupendra5
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random