Challenge - 5 Problems
Laravel Login & Logout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens after a successful login in Laravel?
Consider a Laravel application using the built-in authentication system. After a user submits correct credentials, what is the typical behavior of the application?
Attempts:
2 left
💡 Hint
Think about what Laravel does to remember a logged-in user.
✗ Incorrect
Laravel creates a session to keep the user logged in and redirects them to the page they wanted before login or to the home page.
📝 Syntax
intermediate2:00remaining
Which code correctly logs out a user in Laravel?
You want to log out the currently authenticated user in a Laravel controller. Which code snippet correctly performs the logout?
Attempts:
2 left
💡 Hint
Look for the method that ends the user session.
✗ Incorrect
The correct method to log out a user is logout() on the Auth facade.
❓ state_output
advanced2:00remaining
What is the value of Auth::check() after logout?
In a Laravel controller, after calling
Auth::logout(), what will Auth::check() return?Laravel
<?php Auth::logout(); return Auth::check() ? 'Logged In' : 'Logged Out';
Attempts:
2 left
💡 Hint
Think about whether the user is still authenticated after logout.
✗ Incorrect
After logout, Auth::check() returns false, so the output is "Logged Out".
🧠 Conceptual
advanced2:00remaining
Why use middleware 'auth' in routes for login-required pages?
In Laravel, why do we apply the
auth middleware to routes that require a user to be logged in?Attempts:
2 left
💡 Hint
Middleware controls access based on authentication status.
✗ Incorrect
The auth middleware checks if the user is logged in and redirects to login if not.
🔧 Debug
expert3:00remaining
Why does the logout not clear the session in this code?
Given this Laravel controller method:
Users report they remain logged in after logout. What is the likely cause?
public function logout() {
Auth::logout();
return redirect('/login');
}Users report they remain logged in after logout. What is the likely cause?
Laravel
public function logout() {
Auth::logout();
return redirect('/login');
}Attempts:
2 left
💡 Hint
Think about what else besides logout() is needed to fully clear user session.
✗ Incorrect
Calling Auth::logout() logs out the user but does not clear the session data. You should also call request()->session()->invalidate() to clear the session.