Adding cookie session store back to Rails API app

后端 未结 4 681
天命终不由人
天命终不由人 2020-11-29 02:13

I have a Rails-API app. More or less \"out of the box\" but I want to add back cookie-based session store. Here is what I\'ve done:

app/controllers/application_contr

4条回答
  •  渐次进展
    2020-11-29 02:48

    This line is ignored because you are not using the full Rails stack:

    ::Rails.application.config.session_store :cookie_store,
      :key => '_namespace_key'
    

    So instead, your session is using the default session key set here. However, you can pass these arguments directly by replacing:

    config.middleware.insert_after 
      ActionDispatch::Cookies, ActionDispatch::Session::CookieStore
    

    with:

    config.middleware.insert_after
      ActionDispatch::Cookies, ActionDispatch::Session::CookieStore,
      :key => '_namespace_key'
    

    Here's a full list of options you can pass (with a rough idea of their defaults, since some may be overridden by modules in Rails).

提交回复
热议问题