Skip to content

Commit

Permalink
Add custom controller documentation to README (#234)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikkel Malmberg <[email protected]>
  • Loading branch information
StevenClontz and mikker authored Sep 18, 2024
1 parent 8835038 commit 061599b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ config.action_mailer.default_url_options = {host: "www.example.com"}
routes.default_url_options[:host] ||= "www.example.com"
```

Note as well that `passwordless_for` accepts a custom controller. One possible application of this
is to add a `before_action` that redirects authenticated users from the sign-in routes, as in this example:


```ruby
# config/routes.rb
passwordless_for :users, controller: "sessions"
```

```ruby
# app/controllers/sessions_controller.rb

class SessionsController < Passwordless::SessionsController
before_action :require_unauth!, only: %i[new show]

private

def require_unauth!
return unless current_user
redirect_to("/", notice: "You are already signed in.")
end
end
```

### Route constraints

With [constraints](https://guides.rubyonrails.org/routing.html#request-based-constraints) you can restrict access to certain routes.
Expand Down

0 comments on commit 061599b

Please sign in to comment.