I'm building a Sinatra app using Rack and ActiveRecord, and after Post "/login" is called I'm attempting to set a session hash key session[:user_id] equal to the User.id.
@user = User.find_by(:username => params[:username])
if @user && @user.authenticate(params[:password])
session[:user_id] = @user.id
redirect "/teams"
I have the enable :sessions and set :session_secret, "my_secret" set in the application controller. In pry The session[:user_id] is properly set, but after the redirect the session[:user_id] key disappears. The rest of the session hash persists, but only the key and value I set doesn't. I've also attempted to use:
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:secret => 'your_secret'
Which causes this message to appear after redirect
#<Rack::Session::Abstract::PersistedSecure::SecureSessionHash:0x3fd6ec91f480 not yet loaded>
Could it be bad versions of Sinatra or Rack? I'm running Sinatra 2.1.0 and Rack 2.2.3.