Class: Leash::Client::AuthFacade

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/client.rb

Overview

‘leash.auth` — sync, non-throwing wrapper around Auth.get_user.

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ AuthFacade

Returns a new instance of AuthFacade.



104
105
106
# File 'lib/leash/client.rb', line 104

def initialize(request)
  @request = request
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/leash/client.rb', line 126

def authenticated?
  !user.nil?
end

#userLeash::User?

Note: this method reads ONLY the ‘leash-auth` cookie from the request. `Authorization: Bearer <jwt>` headers are deliberately NOT used for identity resolution here — they’re reserved for env-fetch fallback + CLI/agent flows. To get the user from a Bearer token, you’d hit ‘/api/auth/me` directly with that token.

Returns:

  • (Leash::User, nil)

    the authenticated user, or ‘nil` when not authenticated. Never raises — swallows decode errors so handlers can branch with a clean `if user.nil?`.



117
118
119
120
121
122
123
# File 'lib/leash/client.rb', line 117

def user
  Leash::Auth.get_user(@request)
rescue Leash::AuthError
  nil
rescue StandardError
  nil
end