mcordell / grape_devise_token_auth

Grape compatibility for devise_token_auth + devise + rails setup
MIT License
41 stars 29 forks source link

Implement an "authenticate_user" helper that doen't fail #3

Closed cmolina closed 9 years ago

cmolina commented 9 years ago

It could be very useful if I can make controllers return information customized to a user if he/she is logged in, otherwise return default information.

Right now I must rescue the error by doing something like this:

begin
  user = authenticate_user!
  info = user.some_specific_info
rescue => error
  info = generic_info
ensure
  present info
end

I'd love to have a helper that doesn't fail (nor throw 400 error), so the following code will be equivalent:

user = authenticate_user     # there is no "!"
if user
  info = user.some_specific_info
else
  info = generic_info
end
present info

Thank you in advance.

cmolina commented 9 years ago

@mcordell would you accept a PR with a proposal?

mcordell commented 9 years ago

I think that is a solid idea and would definitely look at a PR

cmolina commented 9 years ago

There it is. I also edited the README.md with a small description.

mcordell commented 9 years ago

Closed in #4