Skip to content

Conversation

@wilburhimself
Copy link
Contributor

Closes #206

This PR adds support for scoping and nesting of Passwordless routes.

Changes made

  1. Updated passwordless_for method in router_helpers.rb to:

    • Accept a block for scoping
    • Properly handle route generation within scopes
    • Maintain backward compatibility with existing usage
  2. Added comprehensive tests in router_helpers_test.rb to verify:

    • Route generation within scopes
    • URL helpers work correctly with scoped routes
    • All authentication endpoints function as expected within scopes
  3. Updated the README to document the new scoping functionality with examples

The implementation now allows you to use Passwordless routes within any Rails scope, such as:

Rails.application.routes.draw do
  scope ":locale" do
    passwordless_for :users
  end
end

This will generate routes like:

  • /:locale/users/sign_in
  • /:locale/users/sign_in/:id
  • /:locale/users/sign_out

And the corresponding URL helpers:

  • users_sign_in_path(locale: 'en')
  • users_sign_out_path(locale: 'en')

The changes in this PR are fully backward compatible, so existing implementations will continue to work as before.

Copy link
Owner

@mikker mikker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing. Question

Comment on lines 49 to 53
if block_given?
scope(defaults: pwless_resource.defaults, &block)
instance_exec(&scope_block)
else
instance_exec(&scope_block)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this solves the problem described?

This talks about running passwordless_for with a block, not inside a scope block?

If block is passed, it runs the block first, then runs passwordless_for exactly like it does now?

Maybe I'm reading it wrong?

@wilburhimself
Copy link
Contributor Author

wilburhimself commented Sep 22, 2025

@mikker You're absolutely right! I've pushed a fix in the latest commit.

The route definitions now properly execute within the provided scope context instead of alongside it. When a block is given, the passwordless routes are now correctly nested within that scope.

image image

The key fix was restructuring the logic so that scope_block (containing the route definitions) runs inside the provided block's context rather than separately.

Could you take another look when you have a chance? The scoping should work as intended now.

Thanks for the feedback!

@wilburhimself
Copy link
Contributor Author

@mikker 👋🏽

@mikker
Copy link
Owner

mikker commented Oct 4, 2025

Thank you for this. Patience, please. I'll get to it eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support scoped routes

2 participants