Rails 5 – API Only – Enable Cookies and Sessions

So you’ve been trying a lot of trial and errors just to enable cookie based session on a API only rails app? Are you trying to customize the cookie expiration but it simply defaulting to default session only cookies? The solution is quite simply though and here it is.

In your config/application.rb, you set the cookie parameters upon calling the middleware.

# ... require and other codes here

module AppNameHere
  class Application < Rails::Application
    config.api_only = true

    config.middleware.use ActionDispatch::Cookies
    config.middleware.use ActionDispatch::Session::CookieStore, key: '_coookie_name', expire_after: 30.days

This entry was posted in Ruby, Web Development and tagged , . Bookmark the permalink.

Related Posts

One Response to Rails 5 – API Only – Enable Cookies and Sessions

  1. Pingback: GraphQL/ Rails 422 Unprocessable Entity – Saving token to Session – Config9.com

Leave a Reply

Your email address will not be published. Required fields are marked *