Complete the code to set a permanent signed cookie for remembering the user.
cookies.permanent.signed[:user_id] = [1]We use user.id to store the user's ID securely in a permanent signed cookie.
Complete the code to find the user by the ID stored in the signed cookie.
User.find_by(id: cookies.signed[:[1]])remember_token or current_user.The cookie key used to store the user ID is user_id.
Fix the error in the method that sets the remember token cookie.
cookies.[1][:remember_token] = user.remember_tokensigned without permanent causes the cookie to expire quickly.temporary which expires when the browser closes.We use permanent to make the cookie last for 20 years, enabling 'remember me' functionality.
Fill both blanks to create a method that forgets the user by deleting cookies.
cookies.delete(:[1]) cookies.delete(:[2])
session_id or auth_token.We delete both user_id and remember_token cookies to fully forget the user.
Fill all three blanks to complete the user authentication method using remember me cookies.
if (user_id = cookies.signed[:[1]]) && (user = User.find_by(id: user_id)) && user.authenticated?(:[2], cookies[:[3]]) log_in user end
The method checks the signed user_id cookie, then authenticates the user with the remember token stored in remember_token cookie.