https://github.com/legalforce-oss/hanami-authentication
https://github.com/legalforce-oss/hanami-authentication
authentication gem hanami ruby
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/legalforce-oss/hanami-authentication
- Owner: legalforce-oss
- License: mit
- Created: 2017-10-02T07:32:11.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-24T09:23:09.000Z (almost 8 years ago)
- Last Synced: 2025-06-14T19:46:33.984Z (4 months ago)
- Topics: authentication, gem, hanami, ruby
- Language: Ruby
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Hanami::Authentication
[](https://badge.fury.io/rb/hanami-authentication)
`Hanami::Authentication` is simple authentication helpers for [hanami-controller](https://github.com/hanami/controller)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'hanami-authentication'
```## Usage
### Setup
```ruby
# application.rb
controller.prepare do
include Hanami::Authenticationbefore authenticate # This will use callbacks if authentication is failed.
before authenticate! # This will force to halt by 401 if authentication is failed.
after_session_expired do # This will be called if authenticate method is called when session is expired.
flash[:error] = 'The session is expired.'
redirect_to routes.root_path
endafter_authentication_failed do # This will be called if authenticate method is called when user has not logged in.
flash[:error] = 'Please login'
redirect_to routes.root_path
end
end
```### Methods
#### Login example
```ruby
# in_your_login_action.rb
def call(params)
email = params[:email]
password = params[:password]
remember_me = params[:remember_me]@current_user = @repository.find_by_email(email)
if match_password?(@current_user, password)
login(@current_user, remember_me: remember_me)
flash[:success] = 'Successful logged in'
redirect_to routes.root_path
else
flash[:error] = 'Email or password is incorrect'
redirect_to routes.root_path
end
end
```#### Logout example
```ruby
# in_your_login_action.rb
def call(params)
logout
end
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/legalforce/hanami-auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Hanami::Auth project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unhappychoice/hanami-authentication/blob/master/CODE_OF_CONDUCT.md).