title: API Devise JSON authentication / registrations / sessions
body: <p>I've created a Rails 4 app using the rails-api gem. I have my application controller which inherits from ActionController::API.</p>
  
  <p>My routes file:</p>
  
  <pre><code>namespace :api do
      namespace :v1 do
         devise_for :users
         resources :friends
      end
  end
  </code></pre>
  
  <p>I have a user model which I have ran a migration to add devise attributes. The user model also has attributes which are not specific to devise, such as first_name and last_name.</p>
  
  <p>I then have a token_authentication model which stores the users token.</p>
  
  <p>I'd like to use the current version of Deivse for the registration / sessions / authentication of users in my app. </p>
  
  <p><strong>My question is</strong> how can I use Devise registration controllers / session controllers to accept JSON format, create a user / session and send a JSON response. I want to enforce user authentication on every request to the API, except for a User create action. I'd need to be able to add in my token code in to Devise so that on the creation of users it also created a token, and on the sessions / authentication it checked for the token.</p>
  
  <p>Any help or suggestions would be greatly appreciated.</p>
  
  <p>If there's any additional info I can provide to help understand my issue, please let me know.</p>
  
  <p>Many thanks</p>
  
  <p>Lee</p>