Pankaj Nagla

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

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?