Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memorize current_#{group_name} to avoid error #722

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/devise_token_auth/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ def devise_token_auth_group(group_name, opts={})
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{group_name}!(favourite=nil, opts={})
unless #{group_name}_signed_in?
mappings = #{mappings}
mappings.unshift mappings.delete(favourite.to_sym) if favourite
mappings.each do |mapping|
set_user_by_token(mapping)
end

unless current_#{group_name}
return render json: {
errors: ["Authorized users only."]
Expand All @@ -46,12 +40,14 @@ def authenticate_#{group_name}!(favourite=nil, opts={})
end

def #{group_name}_signed_in?
#{mappings}.any? do |mapping|
set_user_by_token(mapping)
end
!!current_#{group_name}
end

def current_#{group_name}(favourite=nil)
@current_#{group_name} ||= set_group_user_by_token(favourite)
end

def set_group_user_by_token(favourite)
mappings = #{mappings}
mappings.unshift mappings.delete(favourite.to_sym) if favourite
mappings.each do |mapping|
Expand Down