Skip to content

Instantly share code, notes, and snippets.

@juque
Created July 5, 2021 10:26
Show Gist options
  • Save juque/0ac959efb8716fa2f44a4158de807a50 to your computer and use it in GitHub Desktop.
Save juque/0ac959efb8716fa2f44a4158de807a50 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def logged_in?
session[:access_token].present?
end
def bootic_client
@bootic_client ||= BooticClient.client(:authorized, access_token: session[:access_token]) do |new_token|
Rails.logger.info "Renewed access token"
session[:access_token] = new_token
end
end
helper_method :current_shop
protected
def login_required
redirect_to root_url and return unless logged_in?
end
def bootic_root
@bootic_root ||= bootic_client.root
end
def current_shop
@current_shop ||= bootic_root.shops.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment