0.0
The project is in a healthy, maintained state
Easy database persisted sessions for Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Development

Runtime

~> 2.2
>= 5.2, <= 7.0
~> 0.2
 Project Readme

Ez::Sessions

A simple ActiveRecord model for storing user sessions in the database and encode/decode tokens. Works perfectly for API-based apps.

Installation

Add this line to your application's Gemfile:

gem 'ez-sessions'

Use built-in generators:

rails generate ez:sessions:install
rails generate ez:sessions:migrations

Usage

Extend your module with api

module Auth
  extend Ez::Sessions::API
end

Examples:

session = Auth.create_session(user_id: 1, user_agent: 'Postman', expires_at: 90.days.from_now)
session.user_id # => 1
session.user_agent # => 'Postman'
session.expires_at.to_s # => '2021-10-02 14:18:21 UTC'
session.token # => Enctyped session token. Can be used for auth http headers like Authrorization Bearer

decoded_session = Auth.decode_session(session.token)
session == decoded_session.id # => true

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.