I found solution for above situation, here I want to share it with you, so someone can get help from that.
First create session based on if `wantsurl` isn't empty in 'moodle/auth/userkey/auth.php' after line number 162 like.
While I cannot help you with your query, I have used the auto-enroll plugin and found a serious issue.
I am not sure if it is exactly because of the auto_enroll plugin; but that was the only addition I made to my site before I ran into the issues below.
The enroll into course 'when course is opened' works fine; but the 'enroll on login' created issues for me.
All the users of my site (old and new) got enrolled into the courses where the auto_enroll plugin was used.
For some reason, the installation size started increasing rapidly and within one day, the Moodle installation size went from 5.5 GB to around 50 GB, which is the limit of my server space.
In less than 24 hours, the website crashed.
I had to reinstall everything from a older back-up.
So, if you have enabled 'enroll on login' option, keep an eye on the installation size.