Module: Brevio::Session::WithSessionLogin

Extended by:
ActiveSupport::Concern
Defined in:
lib/brevio/session/with_session_login.rb

Instance Method Summary collapse

Instance Method Details

#brevio_logged_in?Boolean

Returns a boolean flag indicating whether the current client has a Brevio session cookie set, and whether this cookie contains a user ID.

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/brevio/session/with_session_login.rb', line 49

def brevio_logged_in?
  brevio_session, = fetch_session
  brevio_session&.dig(:user_id).present?
end

#fetch_brevio_sessionObject

Fetches the Brevio session from Redis, based on the encrypted key stored in the client’s cookie. Returns nil if there’s no session present.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brevio/session/with_session_login.rb', line 25

def fetch_brevio_session
  brevio_session, redis_key = fetch_session
  return nil if brevio_session.nil?
  if brevio_config.debug?
    brevio_config.logger.info "[brevio-session] Found session #{brevio_session.inspect}"
  end
  refresh_session(redis_key) unless params.transform_keys(&:underscore)[:no_session].present?
  brevio_session
rescue RuntimeError => e
  brevio_config.logger.error "[brevio-session] #{e.message}"
  nil
end

#fetch_brevio_session!Object

Calls the above function, but raises an exception if the session isn’t present.

Raises:



39
40
41
42
43
44
# File 'lib/brevio/session/with_session_login.rb', line 39

def fetch_brevio_session!
  brevio_session, redis_key = fetch_session
  raise NilSession, 'Brevio session was nil' if brevio_session.nil?
  refresh_session(redis_key) unless params.transform_keys(&:underscore)[:no_session].present?
  brevio_session
end