Love Letter from a horse to another
As it turns out the best way to set extra sessions stuff or cookies when you use devise is through a method hook provided by warden.
Warden provides 2 hooks that are very useful: after_set_user and before_logout. In a rails app you would put these hooks in an initializer in config/initializers/<yourfile>.rb.
The hook looks like this:
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
if record && warden.authenticated?(options[:scope])
#... your magic
end
end
Within the block the 3 parameters yielded are:
The object warden has access through pretty much anything, session data, env data, cookies, strategies etc.
The thing that surprised me was that warden.session is stored inside a key (“warden.user.#{scope}.session”) inside the main session object. So how do you manipulate the main session object?
The answer happens to be simple: warden.env['rack.session'] will bring back everything in the session.
{"_csrf_token"=>"#{token}",
"warden.user.#{scope}.key"=>
["#{resource.class}", ["#{resource.to_key}"], "#{resource.salt}"],
"warden.user.#{scope}.session"=>
... anything that you set through warden.session[key] => value ...
}
And you manipulate it as you would expect warden.env['rack.session']['foo'] = ‘bar’
For more info on callbacks https://github.com/hassox/warden/wiki/Callbacks

This past weekend I finished listening to In The Plex. This book is just awesome. If you have been in web development since before google existed & been following google, you must read this book. For me, it was like taking a stroll down memory lane, filling the gaps of my knowledge. Whether because it was something that I didn’t have the time to follow or it was very much a behind the door event, it’s pretty much covered.
The book goes over Google’s timeline in multiple passes, from the founder point of view, from the search point of view, from the China point of view and so on. Each time it paints the picture with more details.
My main takeaway is I have worked a few times at really cool places on cool projects and we, myself nor the company, really didn’t understand what we had going on nor the implications of what we were tapping into. More than once in the past month I have been reminded of how incredibly successful some product I worked on were and we didn’t have a clue about it. There is something to be said about sheer perseverance & vision.
While sure by themselves it’s not enough in most cases, when coupled with a basic ability to execute it makes the whole difference in the world.
Also while reading the book it made me think about problems that I worked on and I still believe have not been solved yet among giving a bunch of ideas for businesses.
If you have been curious about anything Google, how they started, how they manage/hire/develop products this is the definite book.
Watch live video from Startup Lessons Learned on Justin.tv
Watch live video from Startup Lessons Learned on Justin.tv
Watch live video from Startup Lessons Learned on Justin.tv
Watch live video from Startup Lessons Learned on Justin.tv
Watch live video from Startup Lessons Learned on Justin.tv
Watch live video from Startup Lessons Learned on Justin.tv
Watch live video from Startup Lessons Learned on Justin.tv