I am trying to login users programmatically in Drupal 8. Here goes my code:
if(isset($uid)) {
$user = User::load($uid);
user_login_finalize($user);
$user_destination = \Drupal::destination()->get();
$response = new RedirectResponse($user_destination);
$response->send();
exit(0);
}
I am getting the message 'Session opened for...' in watchdog. But the user is not logged in. Can someone tell me whats wrong with my code?
.
)? And your$base_url
is set correctly or unset in the settings file?