class Macros::Auth::SignOut

Signout the given user. The user can be passed in the context.

@example signout a user specified in the context (:scope or :model)

step Macros::Auth::SignOut()

@example signout the user passed in ctx

step Macros::Auth::SignOut(user_key: :impersonated_user)

Public Class Methods

new(user_key: nil) click to toggle source

@return [Macro::Auth::SignOut] step macro instance @param user_key [Hash] ctx key under which is the user which we want to signout

# File lib/macros/auth/sign_out.rb, line 15
def initialize(user_key: nil)
  @user_key = user_key
  @user = nil
end

Public Instance Methods

call(ctx, warden:, **) click to toggle source

Performs a step by signout the given user @param ctx [Trailblazer::Skill] tbl context hash

# 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) click to toggle source
# 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