rails devise jwt auth tutorial for rails api only mode

Sdílet
Vložit
  • čas přidán 2. 06. 2024
  • This is a revision of a blog post I released at the end of 2020. It has been brought up to date with the newest version of ruby 3.2.0 and rails 7. I've also created a GitHub template for this if you'd like to fast track to put this into practice with a bit less setup time.
    GitHub Template: github.com/DakotaLMartinez/ra...
    Blog Post: dakotaleemartinez.com/tutoria...
    Postman collection: www.postman.com/orange-capsul...
    0:00 Intro
    2:25 Creating the app
    4:26 rack-cors
    5:22 Add gems
    6:16 Configure devise
    7:45 Create User
    8:55 Create controllers
    10:23 Customize routes
    11:43 Devise JWT config
    13:30 revocation strategy
    20:00 UserSerializer
    22:00 Update controllers
    29:00 Postman testing
    29:50 DisabledSessionError
    33:40 RackSessionFix
    36:28 Successful login
    37:30 Logout with token
    39:30 GET /current_user
    44:20 GitHub template
    47:15 Use Template
    50:05 Outro & Next Steps
  • Věda a technologie

Komentáře • 32

  • @diegoherrera3381
    @diegoherrera3381 Před měsícem

    People like you make coding world a better place! So thankful for this tutorial!

  • @etoilehime8159
    @etoilehime8159 Před 11 měsíci +2

    thank you I had some issues with devise and rails api I'm still learning Rails thanks a lot for this amazing tutorial

  • @captainunderdog
    @captainunderdog Před rokem

    Thanks for the tutorial. I had an issue with not getting the token, but sorted it out. Thanks again

  • @alexandredomingosfilho5275
    @alexandredomingosfilho5275 Před 3 měsíci

    This is the best tutorial I've seen on devise and JWT in Rails app. Thanks a lot man!

  • @echchafykyotmane6006
    @echchafykyotmane6006 Před 6 měsíci +1

    A new sub to a well-deserved tuto maker, Thank you so much for this video and more for the great article 🤯

  • @larrydanso1129
    @larrydanso1129 Před 11 měsíci +1

    Great video. Can you look at adding up rspec-rails test bed to the endpoints. I don't mind us hacking it away together

  • @the_silver_liningg
    @the_silver_liningg Před 5 měsíci

    This was great! Thank you!

  • @user-px1vl7tb9t
    @user-px1vl7tb9t Před 7 měsíci

    thank you for this awesome tutorial

  • @HemershonSilva
    @HemershonSilva Před 5 měsíci

    your video helped a lot, thank you👏

  • @cherukukishore3568
    @cherukukishore3568 Před 23 dny

    When i give wrong credentials it's sending plain text like "Invalid email or password". How we can get the JSON formatted message? because react throwing error. How can we handle this? Can you please help me on this?

  • @jordanfox3782
    @jordanfox3782 Před 2 měsíci

    Awesome content

  • @user-sy2zn3zc9t
    @user-sy2zn3zc9t Před 6 měsíci +2

    Im having an issue where anytime I try and login with postman it just succeeds every time. Even if the email and password are wrong. You got an error saying email and password are invalid

    • @dakotamartinez9152
      @dakotamartinez9152  Před 2 měsíci

      hey there! Have you tried comparing your code to the finished repository linked in the video description?

    • @ken7562
      @ken7562 Před 2 měsíci

      I also had the same issue even when I cloned the template and tested. Then I realized i was doing a GET request to /login instead of a POST request. Not sure why but a GET request to /login with the same body returns a successful login every time with any credentials (invalid or not).

  • @HaliljonJuraboev
    @HaliljonJuraboev Před 7 měsíci

    It was great video. However, in the end when I try to check with postman, it is keeping on returning {"status":{"code":422,"message":"User couldn't be created successfully. Email can't be blank and Password can't be blank"}}.
    I even cloned your repo it is still returning the same error. Do you have any solution for this? Is it may be my PC setting or the gems are no longer functioning as they were?

    • @kefahngwei8101
      @kefahngwei8101 Před 6 měsíci

      Setup params in the registration controller. That's how I solved my issue. also define the create method.

  • @collinsbawa3642
    @collinsbawa3642 Před 8 měsíci

    amazing tutorial

  • @jmarenas8035
    @jmarenas8035 Před 7 měsíci

    Hi! great tutorial. this was a huge help on guiding me to build api only app but I noticed i cannot do password confirmation. I added password_confirmation on the database, allowed it to be accepted and added validates_confirmation_of :password, message: "Passwords does not match." but it wont validate. how do I do this?

    • @dakotamartinez9152
      @dakotamartinez9152  Před 7 měsíci

      Awesome! Glad it was helpful :) Can you clarify what you mean by "it won't validate"? Do you mean that it allows creating of the record even if passwords don't match? The password_confirmation isn't a column in your database, it's a validation feature that's built into devise when you include the :validatable module. You don't need to do anything to enable this validation. I just tested out my GitHub template and sent a request via postman where the password and password_confirmation fields don't match. I get this back: {
      "status": {
      "code": 422,
      "message": "User couldn't be created successfully. Password confirmation doesn't match Password"
      }
      }

  • @user-lg2vk6zv7v
    @user-lg2vk6zv7v Před 7 měsíci

    Great video. I am able to signup a new user. However on attempting login via Postman, I get a 401 error with the message "Signature verification failed". Is there a known fix?

    • @dakotamartinez9152
      @dakotamartinez9152  Před 7 měsíci

      Do you have a repo anywhere I could take a look at? I think this is your Stackoverflow post: stackoverflow.com/questions/77293693/rails-7-api-ony-devise-jwt-signature-verification-failed-on-login. Feel free to add some more information there if you'd like to troubleshoot.

    • @dakotamartinez9152
      @dakotamartinez9152  Před 7 měsíci

      one thing that occurs to me is that if you did use the GitHub template, you'll need to make sure to generate new credentials so the secret key base exists when the config/initializers/devise.rb attempts to use it to configure signature verification. Not sure if that's the issue, but feel free to keep me posted 🙏

    • @user-lg2vk6zv7v
      @user-lg2vk6zv7v Před 7 měsíci

      @@dakotamartinez9152 I think this is actually working. I was just used to seeing the token in the response. It is returned here in the response header. So I will just figure out how to access it. Thanks!

  • @elvisgithinji6957
    @elvisgithinji6957 Před 4 měsíci

    Do you have a guide on password reset with devise jwt?

  • @Teagou
    @Teagou Před 2 měsíci

    I tried this and like others articles of how do JWT with rails, my current_user keeps empty everytime, and always responds unauthorized, i don't know what is wrong 😭😭

    • @dakotamartinez9152
      @dakotamartinez9152  Před 2 měsíci +1

      feel free to share your repo if you'd like me to take a look 🙏 I know this stuff can be a headache, happy to help if I can!

  • @bakhtiyoryusubaliyev9006

    THANK YOU.👍