make:auth command generates a complete authentication system with login, registration, and user management.
Syntax
This command creates all necessary files for a fully functional authentication system in seconds.
Basic Usage
Generate authentication scaffolding:Generated Files
The command creates:- AuthController - Handles login, registration, and logout
- Pre-built UI views for login and registration forms
- Token-based authentication logic
AuthController.php
Located at:App/Controllers/AuthController.php
App/Controllers/AuthController.php
Features
1. Login Endpoint
POST /api/auth/login2. Registration Endpoint
POST /api/auth/register3. Logout Endpoint
POST /api/auth/logout4. Current User Endpoint
GET /api/auth/meBuilt-in UI Views
Login Page
The generated controller includes a styled login form:Registration Page
Similarly styled registration form with validation:Setting Up Routes
After generating auth scaffolding, add routes:routes/api.php
Validation Rules
The generated controller includes comprehensive validation:Login Validation
Registration Validation
Token-Based Authentication
The scaffolding uses base64-encoded JSON tokens:Token Storage
Frontend stores token in localStorage:Token Usage
Include token in API requests:Customizing Authentication
Connect to Database
Replace the demo users array with database queries:Add Remember Me
Extend token expiration:Add Password Reset
Create additional methods:Add Email Verification
Usage Example
Source Code
The auth generation logic:rawr (lines 317-354)
The actual generated AuthController is much more comprehensive than the simplified version shown in the source code above. It includes full login, registration, validation, and token management.
Security Considerations
Password Hashing
Always usepassword_hash():
Password Verification
Usepassword_verify():
Token Expiration
Always validate token expiration:HTTPS in Production
Always use HTTPS for authentication endpoints in production to protect credentials and tokens.Next Steps
Make Model
Create a User model for database storage
Middleware
Protect routes with authentication middleware
Validation
Learn about form validation
Sessions
Manage user sessions