Assumption
I'm using devise token auth
in Rails, and when I try to return values related to user information created with devise token auth
, I get a cookie over capacity
error. If I use model name.all
the error does not occur.
How can I resolve this error?
What we want to solve
- I want to resolve a
ActionDispatch::Cookies::CookieOverflow
error and return the value associated withuser
created withdevise token auth
.
Code
Controller
class Api::V1::PostsController < ApplicationController
def index
# posts = Post.all
posts = current_api_v1_user.posts # ActionDispatch::Cookies::CookieOverflow
render json: posts, status: :ok
end
Error
api_1 | ActionDispatch::Cookies::CookieOverflow (ActionDispatch::Cookies::CookieOverflow):
I tried
- The only thing I could come up with in my research was to use
activerecord-session_store
gem, but I guess I was wrong and the error was not resolved.
gem
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.6'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
・
・
・
AJAX possible
gem 'rack-cors'
gem 'active_model_serializers'
# JWT Doc: https://github.com/jwt/ruby-jwt
gem 'jwt', '~> 2.2'
gem 'devise'
gem 'devise_token_auth'
gem 'activerecord-session_store' # Add
Migaration
class AddSessionsTable < ActiveRecord::Migration[6.0]
def change
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id, :unique => true
add_index :sessions, :updated_at
end
end
config/initializers/session_store.rb
Rails.application.config.session_store :active_record_store,:key => '_my_app_session'