Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Authentication and authorization

Login form and csrf tokens

Here is a summary of the video transcript:

  • CSRF Protection Implementation
    Cross-Site Request Forgery protection is added using Echo middleware. A CSRF cookie is configured with strict same-site, HTTP-only settings, and skipped for asset routes. This ensures requests are validated as originating from trusted sources.

  • Session and Cookie Management
    A helper function is introduced to set authenticated session data in a secure cookie. The session stores the user email and uses encrypted values, with configurable lifetime and proper invalidation logic for logout.

  • Login Controller Logic
    A login handler binds form data, retrieves the user by email, and validates the password using a pepper value from configuration. On success, a session cookie is set and the user is redirected; on failure, a generic error message is returned.

  • Login View and Routes
    A login page is created with email and password fields using existing UI components. Separate GET and POST routes handle rendering the form and processing authentication, with rate limiting applied to prevent brute-force attempts.

  • Manual User Seeding
    Instead of implementing a public signup flow, a user is created directly in the database via seed data. This avoids unnecessary exposure and ensures only authorized admin access.

  • Logout Functionality
    A logout route invalidates the session by setting the cookie’s max age to a negative value. A flash message confirms logout, and navigation elements are conditionally rendered based on authentication state.

  • Authentication Flow Overview
    The system now includes CSRF protection, rate limiting, password validation, secure session cookies, login/logout flows, and protected admin access. Remaining enhancements for a full production-ready authentication system are deferred to a later module.