ankane / authtrail

Track Devise login activity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined method `transform_method='

waqasahmad opened this issue · comments

Getting the following error

undefined method transform_method=' for AuthTrail:Module (NoMethodError)`

when defining AuthTrail.transform_method = lambda do |data, request| in the authtrail.rb file in the initializer

I have the gem installed successfully and other methods seem to work but the transform_method just fails

gem version authtrail (0.1.3)

Hey @waqasahmad, upgrading versions should fix it. transform_method was added in 0.2.2.

@ankane Thanks, what would be the best way to update the gem? I tried bundle update authtrail but its still on the 0.1.3

Also I just checked the 0.2.2 requires activerecord >= 5 I am on 4.2.8 is there any way around this?

You could fork from 0.2.2 to make it work with Active Record < 5, or fork from 0.1.3 and add the transform_method there.

You could fork from 0.2.2 to make it work with Active Record < 5, or fork from 0.1.3 and add the transform_method there.

Thank you. I will give this a go

ok I have now added the method in the 0.1.3 version so no longer getting that error, however when I use that function to store the user on failed logins, it creates the login activity but the user is not captured, any ideas?

Looking at the console logs the email is NULL and it's not doing this part here of the code

data[:user] ||= User.find_by(email: data[:identity])

 SELECT  `users`.* FROM `users` WHERE `users`.`client_id` = 11 AND `users`.`email` IS NULL LIMIT 1
   (0.1ms)  BEGIN
  SQL (6.4ms)  INSERT INTO `login_activities` (`strategy`, `scope`, `success`, `failure_reason`, `ip`, `user_agent`, `referrer`, `context`, `created_at`) VALUES ('...')

If identity is nil, probably need to use a custom identity method (see readme).

If identity is nil, probably need to use a custom identity method (see readme).

sorry, I think I didn't explain properly. The Identity is only coming through if it's a successful auth if not its nil

I tried using the custom method too but still no success. I use both username or email as username in devise.

Not sure where I am going wrong.

@ankane I have it working now. I had to use a request to get the username and then do a look-up to find that user. All working now thanks for all your help

Glad to hear.