The code seems to be right. Could it be possible that you are calling to the function authenticate_user before initializing the DB?
Also I would add a try-except when creating the connection to th DB
try:
connection_pool = psycopg2.pool.SimpleConnectionPool(
minconn=1,
maxconn=10,
user=USERNAME,
password=PASSWORD,
host=HOST,
port=PORT,
database=targetDbName
)
#The conn will be successfully created.
#if not, will jump to the error (and it will tell you what is failing).
except psycopg2.Error as e:
print(f"Error creating connection pool: {e}")