logo

Programmatically Login in Drupal 9

25
October

Programmatically Login in Drupal 9
By: Anonymous | Published On: Mon, 10/25/2021 - 21:03

You can use the function (user_login_finalize) in your custom code.

Example code to login which you can usein your custom code.

$uid is your user id for which you want to login

	$user = User::load($uid);	
	user_login_finalize($user);

You must be use following code in your namespace. If you don't use then user_login_finalize will not work in Drupal 9

use Drupal\Core\DrupalKernel;

Need Help ?