PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 12, 2022

[FIXED] Shopware 6 Authorize customers

 March 12, 2022     shopware, shopware6, symfony     No comments   

Issue

I would like to create a controller for providing downloadable files to a specific customer group. I need to authenticate the customer and check if they are authorized.

I checked the context and the HTTP header but I was unable to find valuable data about the customer.

What would be an appropriate approach?


Solution

To restrict access to your own route to only logged in customers you can use the @LoginRequired annotations, e.g.:

    /**
     * @LoginRequired()
     * @Route("/account", name="frontend.account.home.page", methods={"GET"})
     */
    public function index(Request $request, SalesChannelContext $context, CustomerEntity $customer): Response

Under the hood the annotation will also check the current customer of the SalesChannelContext.

To get the customer group of the current customer, your proposed solution is the way to go:

$salesChannelContext->getCustomer()->getGroup();


Answered By - j_elfering
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing