Ben,

If the session store is set to ActionDispatch::Session::CookieStore then 
everything stored in the session will be stored in the user's browser 
cookie.  So in effect, the 4k cookie limit is the limit on how much you can 
store in the session, which is why it's not recommended to store much more 
than an ID or two in the cookie-based session.  My question was in regard 
to what else he might be storing in the session in addition to whatever 
Devise is putting in there.

Still, it's odd to me that Devise alone could be blowing up the session 
cookie for two logins.

Here's what I would do, just to get a better bead on this.  Put a raise 
session.inspect call in one of your controllers at a point that will 
execute after you've logged in as a regular user and an admin. This will 
trigger a runtime exception and allow you to see what Rails says you have 
stored in session.  Post that here.

CM
 
On Sunday, April 6, 2014 12:50:35 PM UTC-7, Benjamin Wanicur wrote:
>
> Hi Dude and Chris
>
> Chris, it’s worth noting that he is exceed his 4k *cookie* storage limit, 
> not session limit.  I second Chris’ question about "what are you storing in 
> the cookie ?” .  Without seeing any code, I’m just guessing, but typically 
> you should only store light weight stuff in the cookie.  It’s been awhile 
> since I’ve set up Devise, but in general, you should usually just store 
> unique keys that point to values in the session (or other data store) in 
> your cookie.  You should also not store anything sensitive in the cookie. 
>  I’ve used Devise with multiple users logged in at the same time (admin and 
> reg user) without problems.  Maybe you can show us some code ?  Apologies 
> in advance if I am misinterpreting your problem.
>
> Cheers
>
> Ben W
>  
> On April 6, 2014 at 11:53:41 AM, Abiding Dude ([email protected]) wrote:
>
> Hi Chris, a number of Stack Overflow answers to Devise 
> ActionDispatch::Cookies::CookieOverflow mentioned the 4k cookie limit 
> problem with the recommended solution being to use a different store.
>
> https://coderwall.com/p/dqdyig
>
> At this point in testing I'm not storing anything else in session, the 4k 
> limit seems to be exceeded when I login as a customer AND as admin using 
> Devise. Logging into just 1 works perfectly fine, its the second login 
> adding to the cookie that appears to cause the overflow.
>
> I'm not using memcache at the moment and felt hitting the db may not be 
> ideal for performance. Once you login with Devise with session stored in 
> db, will it hit the db every time to verify access to a page or could that 
> be handled by having just the user_id in a cookie session.
>
> So on login store session info in db, set only the user_id in cookie 
> session and use only that  value to enable access to various pages or 
> sections.
>
> I wired up auth from one of the wire it yourself railscasts, it works fine 
> but not ideal for forgot password. Devise is powerful and pretty user 
> friendly cept for this cookie overflow issue. I checked Sorcery v briefly 
> yesterday but per your suggestion will revisit in more detail this 
> afternoon. Thanks for the tip not to wire it myself.
>
> On Sunday, April 6, 2014 9:10:25 AM UTC-7, Chris McCann wrote: 
>>
>> There are other options for authentication in Rails.  Depending on your 
>> needs, Sorcery is a fairly well-written, lighter weight alternative to 
>> Devise: 
>>
>>  https://github.com/NoamB/sorcery
>>
>> I, along with most other experienced Rails developers here, would 
>> strongly discourage writing your own authentication solution.  There's no 
>> need to reinvent something so critical to an app as authentication when 
>> there is battle-tested, community-vetted code already available.
>>
>> The bigger question here, though, is why you're getting the cookie 
>> overflow error.  Does this Stack Overflow post describe your situation? 
>>
>> http://stackoverflow.com/questions/7117200/devise-for-twitter-cookie-overflow-error
>>
>> You should take a close look at what you're storing in the cookie-based 
>> session, in addition to what Devise is stashing there.  
>>
>> If you find for some reason that you have to put more than 4k of data in 
>> the session then a database or memcached session store would certainly 
>> allow that.  Is there a particular reason why neither of these session 
>> stores is an option?
>>
>> Cheers,
>>
>> Chris
>>
>> On Sunday, April 6, 2014 1:25:49 AM UTC-7, Abiding Dude wrote: 
>>>
>>> Am building an ecommerce app and finding a problem with overflow on 
>>> cookies if I have 2 models with Devise.
>>>
>>> The suggested solution via stack overflow is to use the db to get around 
>>> this issue which I'd rather not, or memcache.
>>>
>>> Is there any other solution recommended for authentication? Or maybe 
>>> write my own?
>>>
>>> There's customer login, affiliate login and admin login. Neither will 
>>> login on same browser at same time, but the overflow issue seems to be 
>>> common in exceeding the 4k limit once you do 2 logins using cookies with 
>>> Devise. Other than that its been a very user friendly and quite powerful 
>>> gem. Thanks for any pointers.
>>>
>>   --
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
> ---
> You received this message because you are subscribed to the Google Groups 
> "SD Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to