How to login programmatically with a user id in Drupal 8 and Drupal 9

In Drupal 8/9, programmatically log in using the user_login_finalize() function with the user id. Use the following snippet in any custom module.
copy-icon

Comments

Authors

Read Next