class Macros::Auth::SignOutAllScopes

Sign out users of all scopes

@example

step Macros::Auth::SignOutAllScopes()

@example specify scopes to skip sign out from

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

Public Class Methods

new(except: []) click to toggle source

@return [Macros::Auth::SignOutAllScopes] step macro instance @param expect [Array] list of scopes to skip sign out

# File lib/macros/auth/sign_out_all_scopes.rb, line 15
def initialize(except: [])
  @except = except.is_a?(Array) ? except : [except]
end

Public Instance Methods

call(ctx, **) click to toggle source

Performs a step by sign out users @param ctx [Trailblazer::Skill] tbl context hash

# 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