ankane / authtrail

Track Devise login activity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Q&A] What is auth.winning_strategy and when it is nil?

truongnmt opened this issue · comments

I have a question about this LOD:

def detect_strategy(auth)
  strategy = auth.env["omniauth.auth"]["provider"] if auth.env["omniauth.auth"]
  strategy ||= auth.winning_strategy.class.name.split("::").last.underscore if auth.winning_strategy
  strategy ||= "database_authenticatable"
  strategy
end

What and when auth.winning_strategy will be nil? 🤔

Hey @truongnmt, strategies are a Warden concept. https://github.com/wardencommunity/warden/wiki/strategies

The winning strategy is the one that was selected for authentication. I can't recall which cases it's nil.

I'm wondering on the condition if auth.winning_strategy, can auth.winning_strategy be nil? Hmm I'm skeptical..

Yes, it can 100% be nil, or else the method wouldn't be written that way. I just can't recall the exact situations. Should have left a comment...