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

Filter chain halted as :authenticate_with_token! rendered or redirected Completed 401 Unauthorized #80

Open
Orinameh opened this issue Dec 5, 2016 · 3 comments

Comments

@Orinameh
Copy link

Orinameh commented Dec 5, 2016

When I set before_action :authenticate_with_token! in products controller and I try to create a product after I login from Postman, I get the error "Not authenticated" with the message in my server as "Filter chain halted as :authenticate_with_token! rendered or redirected Completed 401 Unauthorized". Any help on how to resolve this? Thank you in anticipation

@kurenn
Copy link
Owner

kurenn commented Dec 5, 2016

You need to send the Authorization header with a valid token, are you doing this?

@Orinameh
Copy link
Author

Orinameh commented Dec 6, 2016

How do I go about that? I am currently following your method. This is what I have got in the authenticate.rb file @kurenn. All tests are passing but when I make a post request associating a user with another model, in your case, product, from my android app, I get Unauthorized. Please help.

`module Authenticable

def current_user
@current_user ||= User.find_by(auth_token: request.headers['Authorization'])
end

def authenticate_with_token!
render json: { errors: "Not authenticated" }, status: :unauthorized unless user_signed_in?
end

def user_signed_in?
current_user.present?
end

end`

But I get the unauthorized error when I use before_action :authenticate_with_token! in any controller

@kurenn
Copy link
Owner

kurenn commented Dec 24, 2016

Which version of Rails are you using?

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