abevoelker / devise-passwordless

Devise passwordless logins using emailed magic links
MIT License
201 stars 37 forks source link

Exception when ordering of gems wrong #50

Closed ujh closed 5 months ago

ujh commented 7 months ago

While upgrading to v1 (thanks for all the work, BTW!) I ran into the following error:

❯ rails s
=> Booting Puma
=> Rails 7.1.3.2 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/Users/urbanhafner/.rvm/gems/ruby-3.2.2/gems/devise-4.9.3/lib/devise.rb:364:in `block in add_mapping': undefined method `define_helpers' for Devise::Controllers::Helpers:Module (NoMethodError)

In the end I was able to track it down to the ordering of the gems and the monkeypatching of the devise controller helpers.

The error occurs when the I order the gems in the Gemfile like that:

gem "devise-passwordless"
gem "devise"

And goes away, when devise is being loaded first.

Alternatively, I can make the error go away when I comment out the part of monkeypatch.rb that adds a method to Devise::Controllers::Helpers.

abevoelker commented 7 months ago

Well that's not good. We may be able to do something to delay loading that monkeypatch until after the Devise Rails engine loads:

https://github.com/heartcombo/devise/blob/main/lib/devise/rails.rb

I won't have time to work on this for probably close to a week so if you want to take a crack at it feel free! Thanks for reporting

ujh commented 7 months ago

It's not a big deal, as the fix is easy and now documented.

I spent a few minutes looking into it, and it's possible to reproduce the error in CI when you switch the order of the gems there, too. I then ran out of time and couldn't fix the actual issue.

Here's the work in progress: https://github.com/ujh/devise-passwordless/pull/1

Not sure when I'll get around to looking at it again.

ujh commented 6 months ago

In the end the fix was a simple require "devise".