Class: Macros::Auth::SignOut
Overview
Signout the given user. The user can be passed in the context.
Instance Method Summary collapse
-
#call(ctx, warden:) ⇒ Object
Performs a step by signout the given user.
-
#initialize(user_key: nil) ⇒ Macro::Auth::SignOut
constructor
Step macro instance.
- #scope(ctx) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(user_key: nil) ⇒ Macro::Auth::SignOut
Returns step macro instance.
15 16 17 18 |
# File 'lib/macros/auth/sign_out.rb', line 15 def initialize(user_key: nil) @user_key = user_key @user = nil end |
Instance Method Details
#call(ctx, warden:) ⇒ Object
Performs a step by signout the given user
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/macros/auth/sign_out.rb', line 22 def call(ctx, warden:, **) @user = ctx[@user_key] if @user_key ctx[:scope] = scope(ctx) warden_user = warden.user(scope: ctx[:scope], run_callbacks: false) ctx[:model] = warden_user unless @user warden.logout(ctx[:scope]) warden.clear_strategies_cache!(scope: ctx[:scope]) true end |
#scope(ctx) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/macros/auth/sign_out.rb', line 33 def scope(ctx) resource_or_scope = if @user @user elsif ctx[:scope] ctx[:scope] elsif ctx[:model] ctx[:model] else :user end Devise::Mapping.find_scope!(resource_or_scope) end |