Save 36% for Black Friday! Save 36% on GoRails for Black Friday! Learn more
Pankaj Nagla
Joined
Activity
Hello Everyone,
I have started Rails Training Courses, But I can't able to solve this code.
I'm attempting to access current_user from a custom API controller as shown below:
class Api::V1::UserProfileController < ApplicationController
def index
puts current_user.inspect
end
private
def set_default_format
request.format = :json
end
end
To give a bit of context. I'm integrating React into an already existing project. I'm attempting to get the current user that is logged in. But this always returns as nil and when user_signed_in? the method is called, it's always false. However, I'm able to get current_user from the Users Controller. So I feel as though there is an inconsistency in the session. How can I access current_user from the API controller that reflects the state on other controllers?