mikker / passwordless

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

Fix :as option in passwordless_for #174

Closed mikker closed 9 months ago

mikker commented 10 months ago

Fixes #168

@yshmarov, @jpatters thank you for your reports. Could you try and see whether this fixes your problems? Thanks!

yshmarov commented 10 months ago

using gem 'passwordless', github: 'mikker/passwordless', branch: 'fix-routes', passwordless_for :users, at: '/', as: :auth gives me the following routes:

Screenshot 2023-10-22 at 18 59 58

=> looks good

However the tests do not pass.

When callingpasswordless_sign_in(User.first) I get the following errors:

mikker commented 10 months ago

Hmm, that looks weird? Do you use the bundled mailer? It shouldn't use send in this branch: https://github.com/mikker/passwordless/blob/fix-routes/app/mailers/passwordless/mailer.rb#L15-L24

mikker commented 9 months ago

Did you get a chance to look more into this, @yshmarov

jpatters commented 9 months ago

I will try to make some time to test this later this week.

yshmarov commented 9 months ago

Hmm, that looks weird? Do you use the bundled mailer? It shouldn't use send in this branch: https://github.com/mikker/passwordless/blob/fix-routes/app/mailers/passwordless/mailer.rb#L15-L24

It is failing on this line: https://github.com/mikker/passwordless/blob/master/lib/passwordless/test_helpers.rb#L11

with this change it works for me:

      def passwordless_sign_in(resource)
        session = Passwordless::Session.create!(authenticatable: resource)
        # magic_link = Passwordless::Engine.routes.url_helpers.send(
        #   :"confirm_#{session.authenticatable_type.tableize}_sign_in_url",
        #   session,
        #   session.token
        # )
        magic_link = url_for(
          {
            controller: "passwordless/sessions",
            action: "confirm",
            id: session.id,
            token: session.token,
            authenticatable: session.authenticatable_type.singularize.downcase,
            resource: session.authenticatable_type.tableize
          }
        )
mikker commented 9 months ago

Of course, I didn't realise it was the test helpers. Fixed now, thanks!