Rails 6 API Tutorial - Using has_secure_password for Authentication p.22

Опубликовано: 01 Июль 2026
на канале: Rails Pro
3,933
94

In this video series we will build a Rails API from scratch. Backend APIs are useful for serving data to frontend applications, mobile apps or other backend services.

✨ Check out the new version of this video series, which has been updated for Rails 7    • Rails 7 API Tutorial - Create project and ...  

📖 You can also purchase the eBook and code for the new Rails 7 tutorial - https://tomkadwill.gumroad.com/l/rail...

This video covers:
00:00 - Introduction
00:38 - Adding a new password field
01:32 - Using has_secure_password
01:52 - Using bcrypt for the hashing algorithm
02:58 - Adding a password_digest field
03:54 - Adding has_secure_password to the User model
04:23 - Testing user passwords in the rails console
05:15 - Updating authentication specs with the new password field
06:50 - Adding a new test case for when password is invalid
08:50 - Adding logic to check the user's password, to the authentication controller
10:22 - Adding an AuthenticationError class
11:25 - Rescuing AuthenticationError with rescue_from and returning a 401 (unauthorized) status code
12:56 - Tidying up the controller
14:24 - Testing with cURL
16:35 - Some thoughts on other Rails authentication frameworks

If you’re new to this series, you may want to start with part 1:    • Rails 6 API Tutorial - Create project and ...