Auto login

Hello

I have membership plugin with PayPal Express - with Single Payments as payment gateway.
After the user registers and makes the payment he is redirected to the main page of the site. I want that the users should be auto logged in once they are redirected back from paypal.

I already have login redirection in place which will take the user to the specific page i want. So basically what i want is after the successful transaction from paypal the user gets auto logged in and is sent to the page which is configured in login redirection.

I already have the code which is given in the below thread in place in my functions.php
https://premium.wpmudev.org/forums/topic/membership-auto-login

But it is not working. I dont think it is executing this part of code at all. Please guide me how i can achieve this.

Thanks & Regards
Bhavi