Rails5 API with Devise gem

Hi all,

I am using devise gem in my rails5 api. There is a endpoint for login am using my own endpoint for login and when I try to login it works fine but devise related column are not updating like sign_in_count and ip related. can some on help me how can I do those things and any guide to create api with rails5…

Thanks in advance…

Hi all,

I am using devise gem in my rails5 api. There is a endpoint for login am using my own endpoint for login and when I try to login it works fine but devise related column are not updating like sign_in_count and ip related. can some on help me how can I do those things and any guide to create api with rails5..

What do you see in your rails log when you log in? Are any errors shown in the log? When you say "it works fine", what does that mean? Do you have

before_action :authenticate_user!

on one of the controllers you are able to navigate to after you log in? If not, the fact that you can get to one of the routes in that controller means nothing vis-a-vis Devise.

What do you see on a view where you have added this line of ERB:

<%= debug current_user %>

As to the API, the Rails Guide is a pretty good place to start: http://guides.rubyonrails.org/api_app.html

Walter

As this is api we don’t have views. <%= debug current_user %> can’t be done. I have just used devise gem am trying to override the login of devise as devise have its own login process but in api it does not work that way… Correct me am wrong…

As this is api we don't have views. <%= debug current_user %> can't be done. I have just used devise gem am trying to override the login of devise as devise have its own login process but in api it does not work that way.. Correct me am wrong..

I see, didn't get that. I did a quick google, and found this, which may apply in your case then. If you're not using token_authenticatable in your model, then you should add it. http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise/

Walter

Sorry, check the sell-by date on that last one. Look here: https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example

Token was taken out of Devise proper, but it still lives in third-party gems.

Walter

I created a little app builder so I can study features and rebuild them many times to learn. Running it creates an app with jwt token auth and views too.

It’s here: https://github.com/dgleba/bashrail

This: https://github.com/dgleba/bashrail/blob/master/devisejwt.sh is the token auth part.

This was generated by bashrail - https://github.com/dgleba/brail347a22

It’s running here: https://brail347a22.herokuapp.com/

Maybe it could help you.

Hi James
Follow this link: https://myrailsdemo.blogspot.in/2017/12/rails-api-and-reactauthentication.html