api_authentication_gem 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c1a193db7381a68fbc0dcc8794b6d15fd3c929f06cf34be6f49fa3af6bc4c26
|
4
|
+
data.tar.gz: fe5471fe7547a0b680681d3656a26116a059d4627461ec775ff2611d374368e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '004594d70da880033ee0b743a0a74a2fa50f858e020e60bb3c49765d0cd7b8878c00506850c6ee910ccfcd1dbc89b940091b9689dc0c91129935bbfc05698eb9'
|
7
|
+
data.tar.gz: f92710c1a3b4ed520ff1ff9a8cf7cd48722f1a2fcf1460cd90c7ff9b5fb6643e700b1d29c62d448b139f691556cf4d93b28ca7ba1e980ee8bd488bbd3364a9a4
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# ApiAuthenticationGem
|
2
|
+
|
3
|
+
A lightweight and easy-to-use Ruby gem that adds **user signup and login** functionality to your **Rails API** using **JWT authentication**.
|
4
|
+
|
5
|
+
No need to write boilerplate authentication code again — just plug it in, and you're good to go!
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
## ✨ Features
|
10
|
+
|
11
|
+
- ✅ User signup with email uniqueness and password validation (handled by the gem)
|
12
|
+
- ✅ Login with JWT token generation
|
13
|
+
- ✅ Easy integration with any Rails API
|
14
|
+
- ✅ Customizable user model support
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
## 📦 Installation
|
19
|
+
|
20
|
+
Add this line to your Rails application's `Gemfile`:
|
21
|
+
gem 'api_authentication_gem'
|
22
|
+
Then run:
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
🛠 Setup in Your Rails API
|
26
|
+
1. Generate the User Model (if not already created)
|
27
|
+
rails generate model User email:string password_digest:string
|
28
|
+
rails db:migrate
|
29
|
+
|
30
|
+
2. Create a Controller to Handle Auth Actions
|
31
|
+
|
32
|
+
class UsersController < ApplicationController
|
33
|
+
def signup
|
34
|
+
result = ApiAuthenticationGem::Auth.signup(
|
35
|
+
email: params[:email],
|
36
|
+
password: params[:password],
|
37
|
+
user_class: User
|
38
|
+
)
|
39
|
+
|
40
|
+
if result[:error]
|
41
|
+
render json: { error: result[:error] }, status: :unprocessable_entity
|
42
|
+
else
|
43
|
+
render json: { message: result[:message], user: result[:user] }, status: :created
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def login
|
48
|
+
result = ApiAuthenticationGem::Auth.login(
|
49
|
+
email: params[:email],
|
50
|
+
password: params[:password],
|
51
|
+
user_class: User
|
52
|
+
)
|
53
|
+
|
54
|
+
if result[:error]
|
55
|
+
render json: { error: result[:error] }, status: :unauthorized
|
56
|
+
else
|
57
|
+
render json: { token: result[:token] }, status: :ok
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
3. Define Routes
|
64
|
+
In your config/routes.rb file:
|
65
|
+
Rails.application.routes.draw do
|
66
|
+
post 'signup', to: 'users#signup'
|
67
|
+
post 'login', to: 'users#login'
|
68
|
+
end
|
69
|
+
|
70
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_authentication_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adarsh Mishra
|
@@ -45,6 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- README.md
|
48
49
|
- lib/api_authentication_gem.rb
|
49
50
|
homepage: https://rubygems.org/gems/api_authentication_gem
|
50
51
|
licenses:
|