Sha256: dd6c847e6bc7aa4305d9ae7d5a6230a5aa97a28f62f5c12011a053724ef4a3ce

Contents?: true

Size: 769 Bytes

Versions: 2

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

module AuthRails
  module Authentication
    extend ActiveSupport::Concern

    def authenticate_user!
      payload = Services::JwtService.verify_token(
        token: lookup_access_token,
        secret_key: Configuration::Jwt::AccessToken.secret_key
      )

      CurrentAuth.user = AuthRails.resource_class.find_by(email: payload[:sub])

      raise AuthRails.error_class, :unauthenticated unless CurrentAuth.user
    end

    private

    def lookup_access_token
      token_match = request.headers['Authorization']&.match(/bearer (.+)/i)
      token_match[1] if token_match
    end

    def lookup_refresh_token
      cookies[Configuration::Jwt::RefreshToken.cookie_key.to_sym].presence || params[:refresh_token]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auth_rails-1.0.2 app/controllers/concerns/auth_rails/authentication.rb
auth_rails-1.0.0 app/controllers/concerns/auth_rails/authentication.rb