I have a RAILS 5 API setup to handle authentication and basic endpoints. I was able to login and move around the app, but any time I tried to access an endpoint that had
before_action :authenticate_user! I was getting the error 'Authorized users only.'
After searching and searching I ran across a few things. First, there was this thread: https://github.com/lynndylanhurley/devisetokenauth/issues/74
I tried several of those things, and they didn't work. Turns out that cookies are turned off by default in Rails 5, so you can simply add the following to your application.rb file:
Once those two lines are added, check out @dominicwong617's answer and change any reference to
All of that worked for me. I'm not sure how I feel about adding cookie support to the Rails 5 API...seems to kind of go against the point. But this works for now. Refactoring may be in my future.
Here's the full code in Application Controller: