FIX: don't send user IP/UA when not available

FIX: don’t send user IP/UA when not available

diff --git a/lib/discourse_akismet/users_bouncer.rb b/lib/discourse_akismet/users_bouncer.rb
index c36a3a4..b9a58c5 100644
--- a/lib/discourse_akismet/users_bouncer.rb
+++ b/lib/discourse_akismet/users_bouncer.rb
@@ -42,7 +42,6 @@ module DiscourseAkismet
     private
 
     def args_for_user(user)
-      user_auth_token = user.user_auth_token_logs.last
       profile = user.user_profile
 
       extra_args = {
@@ -50,9 +49,7 @@ module DiscourseAkismet
         permalink: "#{Discourse.base_url}/u/#{user.username_lower}",
         comment_author: user.username,
         comment_content: profile.bio_raw,
-        user_ip: user_auth_token.client_ip.to_s,
-        user_agent: user_auth_token.user_agent,
-        comment_author_url: profile.website
+        comment_author_url: profile.website,
       }
 
       # Sending the email to akismet is optional
@@ -60,6 +57,11 @@ module DiscourseAkismet
         extra_args[:comment_author_email] = user.email
       end
 
+      if token = user.user_auth_token_logs.last
+        extra_args[:user_ip] = token.client_ip.to_s
+        extra_args[:user_agent] = token.user_agent
+      end
+
       extra_args
     end
   end

GitHub sha: c109b72e