Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Authentication and authorization

Creating users

Here is a summary of the video transcript:

  • Database Migration Setup
    A new users table is created via migration, including fields for ID, timestamps, email (unique and not null), and password (byte type). Both up and down migrations are defined to create and drop the table.

  • SQL Queries for User Operations
    Queries are implemented to retrieve a user by email, insert a new user, and update an existing user. Each query returns the affected row and uses parameterized inputs for safety.

  • User Model Definition
    A User struct is defined with ID, timestamps, email, and password fields. A helper function converts database rows into the user model.

  • Find User by Email Logic
    A model-layer function retrieves a user by email, normalizing the email to lowercase before querying. The result is mapped into a User struct.

  • Password Validation Structure
    A passwordPair struct is introduced to hold both password and confirmation password. Validation rules enforce required fields and length constraints.

  • Custom Password Match Validation
    A custom validator ensures that password and confirmation password match. The validation is registered so it automatically runs when processing user input.

  • Create User Workflow
    A CreateUser function validates input, constructs query parameters, and inserts a new user into the database. For now, the password is stored in plain text, with hashing deferred to the next step.

  • Transition to Authentication Handling
    The episode concludes by preparing to implement password hashing and authentication logic in the next phase.