Inject code in the header of my template

However, I won’t be able to find the author name before entering in
the loop?

This isn’t completely correct. The global variable $post is set by WP_Query before the Loop begins and is set to the first post in the Loop. Since the main query runs before the template loads that means that $post is also set very early. If you are careful, you can use that variable. It should contain the correct data about the post author on single/singular post pages.