Mam taki kod.
def user_signed_in?
if current_user.nil?
render_error(401, 'User not signed in. Wrong authorization token')
end
end
def current_user
User.find_by(token: http_auth_header)
end
def http_auth_header
if request.headers['Authorization'].present?
request.headers['Authorization'].split(' ').last
else
render_error(401, 'No Authorization token')
end
end
def render_error(code, resource)
if resource.respond_to?(:errors)
resource_name = resource.class.name.demodulize.to_s.downcase.to_sym
render status: code, json: {
status: code,
errors: resource.errors,
resource_name => ActiveModel::Serializer.serializer_for(resource).new(resource)
}
else
render json: {status: code, error: resource.to_s}, status: code
end
end
Zapętla się on jeśli nie jest ustawiony headers[‘Authorization’].
app/controllers/v1/api_controller.rb:21:in
http_auth_header' app/controllers/v1/api_controller.rb:13:in
current_user’
app/controllers/v1/api_controller.rb:34:inrender_error' app/controllers/v1/api_controller.rb:21:in
http_auth_header’
app/controllers/v1/api_controller.rb:13:incurrent_user' app/controllers/v1/api_controller.rb:34:in
render_error’
app/controllers/v1/api_controller.rb:21:inhttp_auth_header' app/controllers/v1/api_controller.rb:13:in
current_user’
app/controllers/v1/api_controller.rb:7:in `user_signed_in?’
Nie bardzo rozumiem, dlaczego po render_error następuje ponowna próba wywołania current_user.