Last active
November 13, 2019 20:19
-
-
Save shawndeprey/630f36b18ad1fcd7aef74ff90f879004 to your computer and use it in GitHub Desktop.
Application controller example for SPA timeout article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::API | |
before_action :check_timeout | |
def check_timeout | |
@user = User.find_by(id: session[:identity]) | |
return render json: {errors:["A user is required."]}, status: 401 if @user.blank? | |
if @user.should_session_remain_active? | |
@user.set_timeout! | |
else | |
reset_session | |
return render json: {errors:["Session timed out."]}, status: 440 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment