Skip to content

Commit

Permalink
Merge pull request #562 from ruimiguelsantos/json_api
Browse files Browse the repository at this point in the history
Return resource with top-level 'type' member.
  • Loading branch information
booleanbetrayal committed Mar 14, 2016
2 parents 46dd5df + 6a6b37b commit 21a1575
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/devise_token_auth/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module DeviseTokenAuth
class ApplicationController < DeviseController
include DeviseTokenAuth::Concerns::SetUserByToken

def resource_data
response_data = @resource.as_json
def resource_data(opts={})
response_data = opts[:resource_json] || @resource.as_json
if is_json_api
response_data['type'] = @resource.class.name.parameterize
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/devise_token_auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def render_new_error

def render_create_success
render json: {
data: @resource.token_validation_response
data: resource_data(resource_json: @resource.token_validation_response)
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def validate_token
end
end

protected
protected

def render_validate_token_success
render json: {
success: true,
data: @resource.token_validation_response
data: resource_data(resource_json: @resource.token_validation_response)
}
end

Expand Down

0 comments on commit 21a1575

Please sign in to comment.