Git Product home page Git Product logo

rails-jwt-auth-tutorial's People

Contributors

hggeorgiev avatar j-vaughan avatar ltfschoen avatar netqyq avatar zakharantoschenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rails-jwt-auth-tutorial's Issues

How to handle refresh token / reauthorization best practice?

Not necessarily an issue or bug, but how would I go about issuing a refresh token?

Sorry if there is a naive question, but if the token expires after 24 hours, I would have to require the user to reauthorize every day, right?

Should I extend the expiration for longer than 24 hours, or send some sort of refresh token alongside the auth response so that the frontend can re-auth behind the scenes?

Hopefully my question makes sense. Thanks for your help - and great tutorial :)

Pat

Token expiry

Does this check for expired tokens? I can't see where it's done.

Keeping Authentication on page reload

So I followed the guide and it's great! ๐Ÿ‘

However, I'm at the point where I authenticate on the frontend and get the auth token back from the server (along with email, username, and whatever else I decide).

Now what I want to be able to do, is when I store the authToken in localStorage, and I refresh the page, it should know that I'm still logged in without me having to relog in.

Was wondering how we would do that? Thanks!

Update to Rails 5.2 needed

The way you get secret_key_base is not working at Heroku for Rails >= 5.2:

# json_web_token.rb
..
JWT.encode(payload, Rails.application.secrets.secret_key_base)

The new way would be:

JWT.encode(payload, Rails.application.credentials.dig(:secret_key_base))

The same is to apply for decode method as well.

NoMethodError

Hello,
Thank you very much for the tutorial.
I tried downloading Github code and getting an error.
I've put the user through console and when I run the curl to get token, I get following message:


Started POST "/authenticate" for 127.0.0.1 at 2019-02-04 00:34:56 +1100
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by AuthenticationController#authenticate as /
Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "authentication"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "[email protected]"], ["LIMIT", 1]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "[email protected]"], ["LIMIT", 1]]
Completed 500 Internal Server Error in 186ms (ActiveRecord: 1.2ms)

NoMethodError (undefined method `credentials' for #ApiApp::Application:0x00000002b65a88):

lib/json_web_token.rb:4:in encode' app/commands/authenticate_user.rb:12:in call'
app/controllers/authentication_controller.rb:5:in `authenticate'


rails -v : Rails 5.0.6

I'm not sure why Rails.application.credentials is undefined.
Is there something I'm missing?
Thank you.

ArgumentError (wrong number of arguments (given 2, expected 0))

I followed the guide and implemented everything as the guide did.

I get this error:

ArgumentError (wrong number of arguments (given 2, expected 0)):
  
app/controllers/authentication_controller.rb:5:in `authenticate'

When I call:

$ curl -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]","password":"123"}' http://localhost:3000/authenticate

Logout

Excellent tutorial, helped me a lot, but I have a question, if I want to log out how should I proceed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.