Created
July 5, 2021 10:26
-
-
Save juque/0ac959efb8716fa2f44a4158de807a50 to your computer and use it in GitHub Desktop.
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::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