Module: YallaAuthRubyClient::ApiControllerAuthentication

Defined in:
lib/yalla_auth_ruby_client/api_controller_authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_userObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yalla_auth_ruby_client/api_controller_authentication.rb', line 7

def authenticate_user
  token = bearer_token
  return false unless token.present?

  begin
    api_client = OpenapiClient::AuthApi.new
    response = api_client.auth_validate_token_get(token)

    if response && response.success
      @yalla_user = response.user
      @current_user = find_or_create_app_user(@yalla_user)
      (@current_user)
      true
    else
      false
    end
  rescue OpenapiClient::ApiError => e
    Rails.logger.error "Authentication failed: #{e.message}"
    false
  end
end

#authenticate_user!Object



29
30
31
32
33
# File 'lib/yalla_auth_ruby_client/api_controller_authentication.rb', line 29

def authenticate_user!
  return if authenticate_user

  render json: { error: 'unauthorized', redirect_uri:  }, status: :unauthorized
end

#current_userObject



35
36
37
# File 'lib/yalla_auth_ruby_client/api_controller_authentication.rb', line 35

def current_user
  @current_user
end

#logoutObject



3
4
5
# File 'lib/yalla_auth_ruby_client/api_controller_authentication.rb', line 3

def logout
  render json: { redirect_uri: ENV["AUTH_URL"] }
end