2

I used sinatra session in my ruby project. After login I write in session[:name] the name of user. If user call some API method I verify session[:name] and if this value is not empty he get response from the server. After logout I clear this value. My code:

 use Rack::Session::Cookie, :expire_after => 86400
 get '/login' do
 session[:name] = params[:username]
 end
 get '/logout' do
 session[:name] = ''
 return 'done'
 end
 error 401 do
 return '401 Unauthorized'
 end
 get '/check_session' do
 if session[:name].to_s.strip.length == 0 || session[:name].to_s!=params[:username]
 return 401
 end
 return session[:name]
 end

This code works good. But if I login from one browser, i.e. Google Chrome, and after that open anther browser, i.e. Mozilla FireFox and call /check_session I get response from server 401 Unauthorized. Why does this happen? And how to fix it?

asked May 8, 2015 at 6:49

2 Answers 2

2

its not a bug. Each browser making own session. And you need to do login after open page in new browser.

answered May 8, 2015 at 6:56
Sign up to request clarification or add additional context in comments.

Comments

1

That isn't a bug, it's expected. A session only lives on one browser.When you launch Firefox, you start a new session. :)

answered May 8, 2015 at 7:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.