Class: Macros::Auth::SignIn
Overview
Sign in the given user. The user is passed in ctx.
Instance Method Summary collapse
-
#call(ctx, model:, warden:) ⇒ Object
Performs a step by signing in the given user.
- #expire_data_after_sign_in(session:) ⇒ Object
-
#initialize(condition: nil) ⇒ Macro::Auth::SignIn
constructor
Step macro instance.
Methods inherited from Base
Constructor Details
#initialize(condition: nil) ⇒ Macro::Auth::SignIn
Returns step macro instance.
9 10 11 |
# File 'lib/macros/auth/sign_in.rb', line 9 def initialize(condition: nil) @condition = condition end |
Instance Method Details
#call(ctx, model:, warden:) ⇒ Object
Performs a step by signing in the given user
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/macros/auth/sign_in.rb', line 15 def call(ctx, model:, warden:, **) return false if @condition && ctx[@condition].blank? = ctx[:sign_in_options] || {} scope = Devise::Mapping.find_scope!(model) expire_data_after_sign_in(session: warden.session_serializer.session) if warden.user(scope) == model && !.delete(:force) # Do nothing. User already signed in and we are not forcing it. true else [:scope] = scope warden.set_user(model, ) end ctx[:current_user] = model true end |
#expire_data_after_sign_in(session:) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/macros/auth/sign_in.rb', line 34 def expire_data_after_sign_in(session:) # session.keys will return an empty array if the session is not yet loaded. # This is a bug in both Rack and Rails. # A call to #empty? forces the session to be loaded. session.empty? session.keys.grep(/^devise\./).each { |k| session.delete(k) } end |