The devise-api gem is a convenient way to add authentication to your Ruby on Rails application using the devise gem. It provides support for access tokens and refresh tokens, which allow you to authenticate API requests and keep the user's session active for a longer period of time on the client side
MIT License
152
stars
22
forks
source link
Fix undefined variable error in controller helper #25
Within lib/devise/api/controllers/helpers.rb the resource_class is being passed into Devise::Api::Responses::ErrorResponse on initialization. resource_class is a method inherited from the devise controllers so unfortunately, if we use authenticate_devise_api_token! in any controller that doesn't inherit from one, the gem will throw for blank, expired and revoked tokens, rather than handling it cleanly and returning the proper error.
I've added what I think is a clean fix for the issue, and some accompanying specs. I'm happy to make any tweaks if needed :)
Within
lib/devise/api/controllers/helpers.rb
theresource_class
is being passed intoDevise::Api::Responses::ErrorResponse
on initialization.resource_class
is a method inherited from the devise controllers so unfortunately, if we useauthenticate_devise_api_token!
in any controller that doesn't inherit from one, the gem will throw for blank, expired and revoked tokens, rather than handling it cleanly and returning the proper error.I've added what I think is a clean fix for the issue, and some accompanying specs. I'm happy to make any tweaks if needed :)
This issue was initially raised here https://github.com/nejdetkadir/devise-api/issues/24#issue-1765280427