rails devise jwt auth tutorial for rails api only mode

  Рет қаралды 4,849

Dakota Martinez

Dakota Martinez

Күн бұрын

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

Пікірлер: 32
@diegoherrera3381
@diegoherrera3381 18 күн бұрын
People like you make coding world a better place! So thankful for this tutorial!
@etoilehime8159
@etoilehime8159 11 ай бұрын
thank you I had some issues with devise and rails api I'm still learning Rails thanks a lot for this amazing tutorial
@alexandredomingosfilho5275
@alexandredomingosfilho5275 2 ай бұрын
This is the best tutorial I've seen on devise and JWT in Rails app. Thanks a lot man!
@dakotamartinez9152
@dakotamartinez9152 2 ай бұрын
Thanks man! I'm glad it was helpful :D
@echchafykyotmane6006
@echchafykyotmane6006 6 ай бұрын
A new sub to a well-deserved tuto maker, Thank you so much for this video and more for the great article 🤯
@dakotamartinez9152
@dakotamartinez9152 6 ай бұрын
Thanks for the sub! I'm glad it was helpful! :)
@captainunderdog
@captainunderdog Жыл бұрын
Thanks for the tutorial. I had an issue with not getting the token, but sorted it out. Thanks again
@the_silver_liningg
@the_silver_liningg 5 ай бұрын
This was great! Thank you!
@user-px1vl7tb9t
@user-px1vl7tb9t 7 ай бұрын
thank you for this awesome tutorial
@HemershonSilva
@HemershonSilva 5 ай бұрын
your video helped a lot, thank you👏
@jordanfox3782
@jordanfox3782 Ай бұрын
Awesome content
@larrydanso1129
@larrydanso1129 11 ай бұрын
Great video. Can you look at adding up rspec-rails test bed to the endpoints. I don't mind us hacking it away together
@collinsbawa3642
@collinsbawa3642 8 ай бұрын
amazing tutorial
@dakotamartinez9152
@dakotamartinez9152 7 ай бұрын
Thank you! Cheers!
@bakhtiyoryusubaliyev9006
@bakhtiyoryusubaliyev9006 Жыл бұрын
THANK YOU.👍
@dakotamartinez9152
@dakotamartinez9152 Жыл бұрын
you're most welcome! :)
@elvisgithinji6957
@elvisgithinji6957 4 ай бұрын
Do you have a guide on password reset with devise jwt?
@cherukukishore3568
@cherukukishore3568 11 күн бұрын
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?
@user-sy2zn3zc9t
@user-sy2zn3zc9t 5 ай бұрын
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 2 ай бұрын
hey there! Have you tried comparing your code to the finished repository linked in the video description?
@ken7562
@ken7562 Ай бұрын
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 7 ай бұрын
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 6 ай бұрын
Setup params in the registration controller. That's how I solved my issue. also define the create method.
@user-lg2vk6zv7v
@user-lg2vk6zv7v 7 ай бұрын
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 7 ай бұрын
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 7 ай бұрын
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 6 ай бұрын
@@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!
@Teagou
@Teagou 2 ай бұрын
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 2 ай бұрын
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!
@jmarenas8035
@jmarenas8035 7 ай бұрын
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 7 ай бұрын
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" } }
Rails API: Token Authentication Part 1 - [006]
14:00
CodeOps Show
Рет қаралды 51 М.
ISSEI funny story😂😂😂Strange World | Pink with inoCat
00:36
ISSEI / いっせい
Рет қаралды 31 МЛН
FOOTBALL WITH PLAY BUTTONS ▶️ #roadto100m
00:29
Celine Dept
Рет қаралды 44 МЛН
маленький брат прыгает в бассейн
00:15
GL Show Russian
Рет қаралды 4,4 МЛН
Времена жизни в Rust
19:29
Bitωise
Рет қаралды 1,9 М.
Action Mailer for Beginners | Ruby on Rails 7
15:24
Deanin
Рет қаралды 3,5 М.
Google Search as We Know It is Gone!
12:35
Waveform Clips
Рет қаралды 121 М.
What Is JWT and Why Should You Use JWT
14:53
Web Dev Simplified
Рет қаралды 1,1 МЛН
Girl camera photo Editing 3d with adobe Photoshop /9/33/Am
0:43
Amir TECh
Рет қаралды 252 М.
🤖Вернулись в ПРОШЛОЕ🤪
0:28
Demin's Lounge
Рет қаралды 88 М.
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 11 МЛН
#miniphone
0:18
Miniphone
Рет қаралды 3 МЛН
Пленка или защитное стекло: что лучше?
0:52
Слава 100пудово!
Рет қаралды 2 МЛН
Fiber kablo
0:15
Elektrik-Elektronik
Рет қаралды 6 МЛН
Купите ЭТОТ БЮДЖЕТНИК вместо флагманов от Samsung, Xiaomi и Apple!
13:03
Thebox - о технике и гаджетах
Рет қаралды 82 М.