A while ago I wrote about, and shared sample code for, adding a role to a user when they log in if their name appears in a file on the server. That was a Drupal 7 sample.
I’ve now updated that for Drupal 9 and created a project in my GitHub. It’s relatively straightforward so I won’t provide a line by line breakdown again.