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

current_user is nil #232

Closed
farihulrouf opened this issue Mar 13, 2016 · 4 comments
Closed

current_user is nil #232

farihulrouf opened this issue Mar 13, 2016 · 4 comments

Comments

@farihulrouf
Copy link

I keep getting, {"error":"You need to sign in or sign up before continuing."}

`class Api::V1::MomentsController < ApplicationController
  skip_before_filter :verify_authenticity_token,
                     :if => Proc.new { |c| c.request.format == 'application/json' }

  acts_as_token_authentication_handler_for User, fallback: :devise  

  def index
    @moments = current_user.moments
  end

  def create
    @moment = current_user.moments.build(params[:moment])  
    if @moment.save
       @moment
    else
      render :status => :unprocessable_entity,
             :json => { :success => false,
                        :info => @moment.errors,
                        :data => {} }
    end
  end
end`

Can anyone see what is wrong with my code?
Why current_user is nil ?

@gonzalo-bulnes
Copy link
Owner

Hello @FarihulR,

Is any Devise callback set in your ApplicationController? What is the request you are performing? Did you check the FAQ?

Regards!

@farihulrouf
Copy link
Author

Waw :-) Thanks for the response!! :)
Here is ApplicationController

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  skip_before_action :verify_authenticity_token

end

@gonzalo-bulnes
Copy link
Owner

Hi @FarihulR,

And what's the request you're performing? It should look (depending on your routing rules) like:

GET https://secure.example.com/?user_email=alice@example.com&user_token=1G8_s7P-V-4MGojaKD7a

@gonzalo-bulnes
Copy link
Owner

@FarihulR I documented the information needed for troubleshooting in the wiki. Please see Asking for help for examples. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants