refactor success and fail authen to function