warden.authenticate (without !) instead of authenticate! when overriding SessionsController

335 views
Skip to first unread message

brahmana

unread,
Jan 26, 2012, 11:37:45 AM1/26/12
to Devise
Hi,

My rails app needs to send out JSON responses and hence I am
overriding SessionsController to achieve that.

Devise::SessionsController uses warden.authenticate! method (the one
with ! - bang). I looked at its implementation and saw that in case of
auth failure, it throws a :warden symbol, catches it and then
delegates the call to the Dvise::FailureApp which does a bit of
juggling and finally hands over the request to "new" method of the
same controller.

On the contrary, warden.authenticate (without the ! - bang) just
returns nil if the auth fails.

This much of effort probably is needed to keep devise flexible.

In my case, since I am overriding the SessionsController, I was
wondering if using the latter (authenticate without !) will keep
things simple. I can check for nil return value and respond back
appropriately.

AFAIK, there aren't any callbacks being run on failure or anything
like that.

So is that acceptable or will I screw up something in the devise setup
by not allowing the FailureApp to be called?

Regards,
Brahmana

@sribrahmana (http://www.twitter.com/sribrahmana)
Reply all
Reply to author
Forward
0 new messages