fixed auth code function