pelargir / auto-session-timeout

Provides automatic session timeout in a Rails application.
MIT License
126 stars 63 forks source link

can you customize this per user? #22

Closed kevinchugh closed 5 years ago

kevinchugh commented 5 years ago

we want orgs to be able to set their own timeout, can this be done? per user or per some other record value?

pelargir commented 5 years ago

I'm not sure I understand the question. The plugin already works per user. The timeout is managed in the session and each user who logs into the Rails app gets their own unique session.

kevinchugh commented 5 years ago

thanks for responding. the read me implies there is a global timeout. i want to know if i can have these 10 users timeout after 10 minutes, but those 20 users timeout after 2 hours.

kevinchugh commented 5 years ago

there's a weird github bug that closes issues, i didn't close this, just fyi

pelargir commented 5 years ago

Correct, the timeout itself applies globally and is not configurable per user. I'm happy to accept pull request, though, if you would like to make this modification yourself.

kevinchugh commented 5 years ago

great, thanks

gsar commented 5 years ago

@pelargir i haven't tried it, but from reading the code it appears that you can leave the global timeout unspecified and set the user specific value in the auto_timeout method on the user mdoel. can you confirm this will remain a supported way of doing per-user timeouts?

/cc @kevinchugh

pelargir commented 5 years ago

It looks like that would work, yes. I have no plans to change it.

pelargir commented 5 years ago

@kevinchugh per @gsar you can achieve what you want by adding an #auto_timeout method to your user model and returning a timeout (in seconds) from there.

class ApplicationController < ActionController::Base
  auto_session_timeout
end

class User < ActiveRecord::Base
  def auto_timeout
    15.minutes
  end
end

Please reopen this issue if that does not work for you.

I've updated the README with these instructions. Thank you both.