Moving if clause for authentication