automatic logout after inactivity/idle

前端 未结 4 2028
半阙折子戏
半阙折子戏 2020-12-29 05:21

How to set up in the rails application that if any user is idle for 30 minutes or a specific period of time he should be automatically get logged out. Can any one give any s

4条回答
  •  盖世英雄少女心
    2020-12-29 05:48

    You should use Timeoutable model trait.

    Timeoutable takes care of veryfing whether a user session has already expired or not. When a session expires after the configured time, the user will be asked for credentials again, it means, he/she will be redirected to the sign in page.

    Options

    Timeoutable adds the following options to devise_for:

    • +timeout_in+: the interval to timeout the user session without activity.

    In your model you need

    devise :timeoutable
    # along with :database_authenticatable, :registerable and other things.
    

    Also, take a look at config/initializers/devise.rb, you can configure timeout value there.

提交回复
热议问题