Module: Workarea::Api::Storefront::Authentication

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/workarea/api/storefront/authentication.rb

Defined Under Namespace

Classes: InvalidError

Instance Method Summary collapse

Instance Method Details

#authentication?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'app/controllers/workarea/api/storefront/authentication.rb', line 23

def authentication?
  regex = ActionController::HttpAuthentication::Token::TOKEN_REGEX
  request.authorization.to_s[regex].present?
end

#current_userObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/workarea/api/storefront/authentication.rb', line 13

def current_user
  return @current_user if defined?(@current_user)

  user = authenticate_with_http_token do |token, options|
    User::AuthenticationToken.authenticate(token, options).try(:user)
  end

  @current_user = user || raise(InvalidError)
end