Class: Macros::Auth::SignOutAllScopes

Inherits:
Base
  • Object
show all
Defined in:
lib/macros/auth/sign_out_all_scopes.rb

Overview

Sign out users of all scopes

Examples:

step Macros::Auth::SignOutAllScopes()

specify scopes to skip sign out from

step Macros::Auth::SignOutAllScopes(except: [:admin])

Instance Method Summary collapse

Methods inherited from Base

register

Constructor Details

#initialize(except: []) ⇒ Macros::Auth::SignOutAllScopes

Returns step macro instance.

Parameters:

  • expect (Array)

    list of scopes to skip sign out



15
16
17
# File 'lib/macros/auth/sign_out_all_scopes.rb', line 15

def initialize(except: [])
  @except = except.is_a?(Array) ? except : [except]
end

Instance Method Details

#call(ctx) ⇒ Object

Performs a step by sign out users

Parameters:

  • ctx (Trailblazer::Skill)

    tbl context hash



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/macros/auth/sign_out_all_scopes.rb', line 21

def call(ctx, **)
  warden = ctx[:warden]

  if @except.empty?
    warden.logout
  else
    (Devise.mappings.keys - @except).each do |scope|
      warden.logout(scope) if warden.authenticated?(scope: scope)
    end
  end

  Macros::Auth::ExpireSessionData.new.call(ctx)
  warden.clear_strategies_cache!
  warden.lock!
end