I need to integrate a functionality where when a user clicks add to cart it should check whether he is a logged in customer or not. If he is a logged in customer the product should be added in cart. Else it should redirect to Login page after logging in the products to be added automatically. I am using event/observer according to this article but no luck.
I am using below approach:-
controller_action_predispatch_checkout_cart_addevent to check the customer login status and redirect to login page id customer is not logged in.
customer_loginevent I am adding the product in cart after customer login.
above solution works on category page, but not working on product detail page. it give me below error:-
main.DEBUG: URI "/magento/checkout/cart/add/uenc/aHR0cDovL25lanJlZWRlbW8ud2ViZXBvd2VyLmJpei9tYWdlMjMxYi9mdXJuaXR1cmUuaHRtbA%2C%2C/product/1/" cannot be accessed with GET method (Magento\Checkout\Controller\Cart\Add)  
Request validation failed for action "Magento\Checkout\Controller\Cart\Add\Interceptor"
Please let me know what is the best practice to achieve this according to Magento2 standard.