No release in over 3 years
Provides Rails generators for authentication, user management, password resets, and mailers, streamlining the setup of secure user authentication in Rails applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 3.1.12
>= 2.5
>= 6.0
 Project Readme

Gem Version

JWT Rails-api auth

JWTRailsAPIAuth is a Rails generator that scaffolds a JWT-based authentication system for rails API with user management, password resets, refresh token rotation, and secure cookie handling. It saves you weeks of setup by providing all the models, controllers, serializers, and mailers you need for a robust, production-ready authentication flow.

Features

  • ๐Ÿ”‘ JWT Authentication
    • Access tokens (short-lived, default 15 min)
    • Refresh tokens (stored securely in HttpOnly cookies)
    • Token rotation + reuse detection
    • Logout everywhere
  • ๐Ÿ‘ค User management
    • User model with secure password
    • Role support (admin, user)
  • โœ‰๏ธ Password reset
    • Password reset tokens (sent in response until now, you can surly sent via email)
  • ๐Ÿ› ๏ธ Rails Generators
    • models (user,refresh_token)
    • controllers (auth, users, password_resets)
    • serializers (user)
    • mailers (user)
    • concern (Authenticatable)
    • initializers (jwt_rails_api_auth)

Installation

Add this line to your application's Gemfile:

gem "jwt_rails_api_auth", "~> 1.0", ">= 1.0.3"

and then run :

bundle Install

Or install it using :

gem install jwt_rails_api_auth

Usage/Examples

Generate the full authentication system:

rails generate auth

Then run:

bundle install  
rails db:migrate  

Whatโ€™s Scaffolded

  • controllers/concerns

    • authenticatable.rb:
      Provides JWT-based authentication methods for controllers, including token encoding/decoding, user authorization, and admin checks.
  • controllers

    • auth_controller.rb:
      Handles login, logout, and refresh token actions.
    • users_controller.rb:
      Manages user creation and allows admins to promote users.
    • password_resets_controller.rb:
      Handles password reset functionality.
  • models

    • user.rb
    • refresh_token.rb
  • initializers

    • jwt_rails_api_auth.rb:
      Template for configuring JwtRailsApiAuth (JWT secret, token expiry, role-based access).
  • serializers

    • user_serializer.rb
  • mailers

    • user_mailer.rb
    • application_mailer.rb
  • migrations

    • create_user.rb
    • create_refresh_token.rb
  • Also insert required gems in your gemfile and add cors

API Routes & Request Details

  • signup
    • header: Content-Type application/json
    • alt text
  • login
    • header: Content-Type application/json
    • alt text

header

  • me (current user)
    • alt text
  • expired or invalid token
    • alt text
  • refresh
    • alt text
  • password resets
    • alt text
    • alt text
  • Logout
    • alt text

๐Ÿค Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Zeyad-Hassan-1/authJWT.

This project follows a Code of Conduct. Please respect it in all interactions.

Authors