Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Authentication and authorization

Barring access to admin

Here is a summary of the video transcript:

  • App Cookie Structure
    An application-wide cookie structure is created to store authentication state and user email. Constants define session keys, and helper functions retrieve and map session values into a typed app struct.

  • Context Integration
    The app data is injected into the request context so it can be accessed throughout the application. This mirrors the flash message setup and ensures authentication data is consistently available during request handling.

  • Authentication Middleware
    An auth only middleware function is implemented to restrict access to protected routes. It checks the authentication flag from the app cookie and redirects unauthenticated users to the login page.

  • Middleware Registration Order
    Middleware is registered sequentially, with cookie store and app context setup occurring before authentication checks. Proper ordering ensures session data is available when evaluated.

  • Controller Rendering Update
    The render function is extended to propagate the app context through the rendering pipeline. This allows UI components to access authentication state.

  • Route Protection Strategies
    Two approaches are explored: applying middleware individually to routes or grouping routes under a common prefix. While grouping simplifies middleware application, it introduces routing complexities that require additional handling.

  • Testing and Debugging
    The middleware is tested by attempting to access admin routes. Redirect behavior confirms correct authentication enforcement, and routing adjustments are made to resolve prefix-related issues.

  • Next Steps
    The next phase involves implementing the login page, controller logic, and adding CSRF protection to improve security before deployment.