mikker / passwordless

πŸ— Authentication for your Rails app without the icky-ness of passwords
MIT License
1.28k stars 89 forks source link

undefined method `after_session_save=' for Passwordless:Module #48

Closed aurels closed 5 years ago

aurels commented 5 years ago

Hello,

I'm trying to use this : https://github.com/mikker/passwordless#customize-the-way-to-send-magic-link

So I add a Passwordless.after_session_save = to my initializer. Ruby tells me it's not defined. I can see in the source code of passwordless (0.6.0) that it's well defined in lib/passwordless.rb.

Am I missing something ? Thanks.

mikker commented 5 years ago

Hi @aurels! That sounds weird. Where are you trying to set this? In an initializer?

aurels commented 5 years ago

Yep @mikker, here is my initializer file :

# Token timeout
Passwordless.timeout_at = lambda { 2.hours.from_now }

# Session Expiry
Passwordless.expires_at = lambda { 72.hours.from_now }

Passwordless.after_session_save = lambda do |session|
  email = @session.authenticatable.email
  link  = users.token_sign_in_url(session.token)

  puts "New connection link generated for #{email}"
  puts "#{link}"

  user    = User.find_by!(email: email)
  account = user.accounts.first

  Mailer.passwordless_link(account, email, link)
end
mikker commented 5 years ago

And you are sure you're using the latest version of the gem (bundle show passwordless) and restarted the server? Just making sure.

aurels commented 5 years ago

Yes :

git:(passwordless) βœ— docker-compose -f docker/development/docker-compose.yml run web bundle show passwordless
/usr/local/bundle/gems/passwordless-0.6.0
aurels commented 5 years ago

I'm glad to read I'm not crazy :p

aurels commented 5 years ago

Here is the full stacktrace in case it may help : https://gist.github.com/aurels/9b13240e8f6945ccc84f3dba1e76d062

Methods :

irb(main):004:0> Passwordless.methods.sort
=> [:!, :!=, :!~, :<, :<=, :<=>, :==, :===, :=~, :>, :>=, :__id__, :__send__, :`, :acts_like?, :alias_attribute, 
:ancestors, :anonymous?, :as_json, :attr_internal, :attr_internal_accessor, :attr_internal_reader, 
:attr_internal_writer, :autoload, :autoload?, :blank?, :cattr_accessor, :cattr_reader, :cattr_writer, :class, 
:class_eval, :class_exec, :class_variable_defined?, :class_variable_get, :class_variable_set, 
:class_variables, :clone, :concern, :concerning, :const_defined?, :const_get, :const_missing, :const_set, :constants, :deep_dup, :default_from_address, :default_from_address=, :define_singleton_method, :delegate, :delegate_missing_to, :deprecate, :deprecate_constant, :display, :dup, :duplicable?, :enum_for, :eql?, :equal?, :expires_at, :expires_at=, :extend, :freeze, :frozen?, :gem, :guess_for_anonymous, :hash, :html_safe?, :in?, :include, :include?, :included_modules, :inspect, :instance_eval, :instance_exec, :instance_method, :instance_methods, :instance_of?, :instance_values, :instance_variable_defined?, :instance_variable_get, :instance_variable_names, :instance_variable_set, :instance_variables, :is_a?, :itself, :kind_of?, :load_dependency, :mattr_accessor, :mattr_reader, :mattr_writer, :method, :method_defined?, :method_visibility, :methods, :module_eval, :module_exec, :mounted_as, :mounted_as=, :name, :nil?, :object_id, :parent, :parent_name, :parents, :prepend, :presence, :presence_in, :present?, :pretty_inspect, :pretty_print, :pretty_print_cycle, :pretty_print_inspect, :pretty_print_instance_variables, :private_class_method, :private_constant, :private_instance_methods, :private_method_defined?, :private_methods, :protected_instance_methods, :protected_method_defined?, :protected_methods, :psych_to_yaml, :psych_yaml_as, :public_class_method, :public_constant, :public_instance_method, :public_instance_methods, :public_method, :public_method_defined?, :public_methods, :public_send, :railtie_helpers_paths, :railtie_namespace, :railtie_routes_url_helpers, :rake_extension, :reachable?, :redefine_method, :redefine_singleton_method, :redirect_back_after_sign_in, :redirect_back_after_sign_in=, :remove_class_variable, :remove_instance_variable, :remove_possible_method, :remove_possible_singleton_method, :require_dependency, :require_or_load, :respond_to?, :send, :silence_redefinition_of_method, :singleton_class, :singleton_class?, :singleton_method, :singleton_methods, :suppress_warnings, :table_name_prefix, :taint, :tainted?, :tap, :thread_cattr_accessor, :thread_cattr_reader, :thread_cattr_writer, :thread_mattr_accessor, :thread_mattr_reader, :thread_mattr_writer, :timeout_at, :timeout_at=, :to_enum, :to_json, :to_param, :to_query, :to_s, :to_yaml, :to_yaml_properties, :token_generator, :token_generator=, :trust, :try, :try!, :unloadable, :untaint, :untrust, :untrusted?, :use_relative_model_naming?, :with_options, :yaml_as]

Something strange to me too :

Passwordless::VERSION
NameError: uninitialized constant Passwordless::VERSION
mikker commented 5 years ago

Maybe try gem open passwordless to browse around and look if the code matches?

aurels commented 5 years ago

OK, it does not :

image

Maybe the 0.6.0 version on RubyGems.org is not the same as on Github ?

mikker commented 5 years ago

We should've checked the CHANGELOG – turns out the feature isn't released yet πŸ˜†

Here's 0.6.0: https://github.com/mikker/passwordless/blob/v0.6.0/lib/passwordless.rb

I'll do a release right away.

mikker commented 5 years ago

0.7.0 is released to Rubygems πŸ‘

aurels commented 5 years ago

Rha! Thanks.

Really useful and well implemented project BTW. Do you have a list of future enhancements somewhere ? I'd be happy to contribute.

mikker commented 5 years ago

I only have the Issues on here but as far as I remember there’s a few features in there.

PRs are very welcome! And thanks 😊 do my best.