August 2025
Intermediate to advanced
270 pages
6h 16m
English
Have you noticed that every time you launch the app you have to sign in again? Mobile app users expect to remain signed in even after they close or background an app. Let’s fix that.
Check out the Authentication concern[24] in the Rails codebase. This module is included in ApplicationController to authenticate users. The #sign_in method persists the user’s ID to an encrypted cookie when they sign in.
| | module Authentication |
| | extend ActiveSupport::Concern |
| | |
| | included do |
| | helper_method :current_user, :user_signed_in? |
| | end |
| | |
| | def sign_in(user) |
| | Current.user = user |
| » | cookies.encrypted[:user_id] = user.id |
| | end |
| | |
| | ... |
Read now
Unlock full access