Commit f52f7261 by liyijie

instance_variable_set when authentication is done

parent 53635017
...@@ -10,6 +10,8 @@ module RailsApiAuthentication ...@@ -10,6 +10,8 @@ module RailsApiAuthentication
klasses = self.class.action_classes klasses = self.class.action_classes
klasses.each do |klass| klasses.each do |klass|
@current_auth = klass.auth!(request) rescue next @current_auth = klass.auth!(request) rescue next
sym = klass.name.underscore.to_sym
instance_variable_set("@current_#{sym}", @current_auth)
break break
end end
render(json: "Unauthorized", status: 401) if @current_auth.nil? render(json: "Unauthorized", status: 401) if @current_auth.nil?
...@@ -22,7 +24,6 @@ module RailsApiAuthentication ...@@ -22,7 +24,6 @@ module RailsApiAuthentication
@klasses = Array(klass_sym).map do |sym| @klasses = Array(klass_sym).map do |sym|
define_method("current_#{sym}") { @current_auth } define_method("current_#{sym}") { @current_auth }
instance_variable_set("@current_#{sym}", @current_auth)
sym.to_s.camelize.constantize sym.to_s.camelize.constantize
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment