ユーザーセッションの有効期限が切れているかどうかを定期的に確認し、期限切れの場合はログインページにリダイレクトできるソリューションを探しています。
私は Authlogic gem を使用しているので、現在のユーザーでテストを行う関数を呼び出しています。
私の USER_SESSION_TIMEOUT は 5 分なので、5:10 分ごとにこの ajax 呼び出しを行います。
<%= periodically_call_remote :url => {:controller => 'user_session', :action => 'check_session_timed_out'}, :frequency => (USER_SESSION_TIMEOUT + 10.seconds) %>
def check_session_timed_out
if !current_user
flash[:login_notice] = "Your session timed out due to a period of inactivity. Please sign in again."
render :update do |page|
page.redirect_to "/user_sessions/new"
end
else
render :nothing => true
end
end
current_user を呼び出すたびに、ユーザー オブジェクトが更新されるため、セッションが 5 分に更新されることに気付きました。
1 つのタブしか開いていない場合は問題ありませんが、check_session_timed_out current_user renew を呼び出すたびに 2 つのタブがある場合、ユーザーを更新するため、セッションが期限切れになることはありません。
何か案が?ありがとう