mikker / passwordless

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

Add callback to customize method of notifying magic link to user #39

Closed ykpythemind closed 5 years ago

ykpythemind commented 5 years ago

I wanted to change the way to notify users of magic link. For example, SMS may notify magic link.

e.g

Passwordless.after_session_save = lambda { |session| session.authenticatable.send_sms_or_something_method } 
ykpythemind commented 5 years ago

Perhaps this change is necessary? Since the test did not work in the local environment, I made this change.

diff --git a/passwordless.gemspec b/passwordless.gemspec
index 33117ce..2d9a90c 100644
--- a/passwordless.gemspec
+++ b/passwordless.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
   s.add_dependency "rails", ">= 5.1.4"
   s.add_dependency "bcrypt", "~> 3.1.11"

-  s.add_development_dependency "sqlite3"
+  s.add_development_dependency "sqlite3", "~> 1.3.6"
   s.add_development_dependency "yard"
   s.add_development_dependency "rubocop"
 end
mikker commented 5 years ago

This is a great addition 👍 thanks!

Can you add a test case and a section to the readme? Then I'll happily merge.

mikker commented 5 years ago

Travis fails from your sqlite dependency update. I'm not sure we need the version requirement – I'd like us to investigate further if this is really a version we need or just something to make your local setup work 😉

ykpythemind commented 5 years ago

thanks! I'm going to add testcase and readme.


The same error with travis-ci occurs in my local environment.

(travis-ci)

$ bin/rails db:migrate RAILS_ENV=test
rails aborted!
LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile.
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:12:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/connection_adapters/connection_specification.rb:191:in `spec'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:952:in `establish_connection'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:60:in `establish_connection'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/railtie.rb:136:in `block (2 levels) in <class:Railtie>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activerecord-5.2.2/lib/active_record/base.rb:27:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/travis/build/mikker/passwordless/lib/passwordless/engine.rb:12:in `block in <class:Engine>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:426:in `instance_exec'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:426:in `block in make_lambda'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:606:in `block (2 levels) in default_terminator'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:605:in `catch'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:605:in `block in default_terminator'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:199:in `block in halting'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:513:in `each'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:513:in `invoke_before'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:131:in `run_callbacks'
/home/travis/.rvm/gems/ruby-2.4.4/gems/activesupport-5.2.2/lib/active_support/reloader.rb:89:in `prepare!'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/application/finisher.rb:63:in `block in <module:Finisher>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
/home/travis/build/mikker/passwordless/test/dummy/config/environment.rb:7:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/application.rb:337:in `require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/engine/commands.rb:9:in `require'
/home/travis/.rvm/gems/ruby-2.4.4/gems/railties-5.2.2/lib/rails/engine/commands.rb:9:in `<top (required)>'
bin/rails:16:in `require'
bin/rails:16:in `<main>'

So, I specified version.

https://github.com/mikker/passwordless/pull/39#issuecomment-460523940

but I didn't commit that changes. It seems like we need to specify version...

mikker commented 5 years ago

Ah, now I get it. Yes, please add the version requirement then 👍

ykpythemind commented 5 years ago

ok, I fixed!

mikker commented 5 years ago

Very nice work, thanks a bunch! 💙💚💛💜❤️