Skip to content

Commit 549b95b

Browse files
author
Alexei
committed
request format in controllers
1 parent e4d473b commit 549b95b

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
jwt_authentication (0.0.1)
4+
jwt_authentication (0.0.2)
55
actionmailer (>= 3.2.6, < 5)
66
actionpack (>= 3.2.6, < 5)
77
devise (~> 3.2)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,6 @@ devise_for :users, module: :jwt_authentication
222222
...
223223

224224
```
225+
_Note: request format will be set to `:json` by before filter `:set_request_format!`, that is plugged to each inherited devise controller.
226+
It is necessary for process action if `warder.authenticate!` falls. It will render view for sessions creating by default,
227+
by in our case, we need json response :unauthorized_

app/controllers/jwt_authentication/concerns/jwt_controller_helpers.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module JwtControllerHelpers
66
included do
77
skip_before_filter :verify_authenticity_token # to avoid Devise check anti forgery token
88
before_filter :allow_params_authentication!
9+
before_filter :set_request_format!
910
end
1011

1112
def render_resource_or_errors(resource, options = {})
@@ -22,6 +23,10 @@ def json_status(bool)
2223

2324
def require_no_authentication
2425
end
26+
27+
def set_request_format!
28+
request.format = :json
29+
end
2530
end
2631
end
2732
end

lib/jwt_authentication/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module JwtAuthentication
2-
VERSION = '0.0.2'
2+
VERSION = '0.0.3'
33
end

0 commit comments

Comments
 (0)