Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shawndeprey
Last active November 13, 2019 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawndeprey/630f36b18ad1fcd7aef74ff90f879004 to your computer and use it in GitHub Desktop.
Save shawndeprey/630f36b18ad1fcd7aef74ff90f879004 to your computer and use it in GitHub Desktop.
Application controller example for SPA timeout article
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