Module: BetterAuth::Sinatra::Helpers

Defined in:
lib/better_auth/sinatra/helpers.rb

Instance Method Summary collapse

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/better_auth/sinatra/helpers.rb', line 16

def authenticated?
  !current_user.nil?
end

#current_sessionObject



6
7
8
9
# File 'lib/better_auth/sinatra/helpers.rb', line 6

def current_session
  data = better_auth_session_data
  data&.fetch(:session, nil) || data&.fetch("session", nil)
end

#current_userObject



11
12
13
14
# File 'lib/better_auth/sinatra/helpers.rb', line 11

def current_user
  data = better_auth_session_data
  data&.fetch(:user, nil) || data&.fetch("user", nil)
end

#require_authenticationObject



20
21
22
23
24
# File 'lib/better_auth/sinatra/helpers.rb', line 20

def require_authentication
  return true if authenticated?

  halt 401, ""
end