Overview
Dashboard Laravel handles all authentication through theAuthController. The authentication system includes login, registration, and logout functionality.
Authentication Routes
| Method | Path | Route Name | Controller Method | Purpose |
|---|---|---|---|---|
| GET | / | home | showLogin | Display login form |
| POST | /login | login | login | Process login |
| POST | /logout | logout | logout | Process logout |
| GET | /signup | signup | showRegister | Display registration form |
| POST | /signup | register | register | Process registration |
Route Definitions
All authentication routes are defined inroutes/web.php and handled by the AuthController:
Login Routes
- Show Login Form
- Process Login
Displays the login page for users to authenticate
AuthController@showLoginReturns: Login view/formExample Usage:The root path
/ serves as the login page, making it the application’s entry point for unauthenticated users.Registration Routes
- Show Registration Form
- Process Registration
Displays the registration form for new users
AuthController@showRegisterReturns: Registration view/formExample Usage:Both GET and POST routes for signup use the same path
/signup but different HTTP methods, following RESTful conventions.Logout Route
Logs out the authenticated user and destroys their session
AuthController@logout
HTTP Method: POST (not GET for security reasons)
Example Usage:
Logout uses POST method to prevent CSRF attacks. Never use GET requests for state-changing operations like logout.
Route Protection
Current Implementation
The authentication routes inweb.php don’t show explicit middleware configuration. However, proper route protection should be implemented:
Consider implementing middleware groups to:
- Protect dashboard routes with
authmiddleware - Prevent authenticated users from accessing login/signup with
guestmiddleware - Add CSRF protection (automatically included in Laravel’s web middleware)
Middleware Usage
Laravel’s default web middleware group is automatically applied to all routes inweb.php:
- CSRF Protection: Validates CSRF tokens on POST requests
- Session Handling: Manages user sessions
- Cookie Encryption: Encrypts cookies
- Validation: Validates incoming requests
Recommended Additional Middleware
- Auth Middleware
- Guest Middleware
- Throttle Middleware
AuthController Methods
TheAuthController handles all authentication logic:
Controller Methods
Displays the login form view
Validates credentials and authenticates the user
Logs out the current user and invalidates the session
Displays the registration form view
Validates input, creates a new user, and authenticates them
Example: Complete Authentication Flow
Ensure your
AuthController implements proper validation, password hashing, and session management for secure authentication.