Week 006 — Root Cause, Login, and a Git Branch That Lied

Two bugs got root-caused this week, and a third introduced itself as soon as login was working.

Week of November 4, 2024

Progress

Resolved the avatar image clearing bug. Two separate issues, both in the same code path:

First, the image processing block was running before the new-vs-existing case statement. When no new image was provided, the path got overwritten with nothing. Moving the block below the conditional fixed it.

Second, the browser was submitting the avatar path as a fully qualified URL on save — https://macbaby.local/uploads/... instead of just /uploads/.... That URL was getting written to the database, overwriting the relative path that was there before. Fixed with a small utility function that uses a regex to strip domain information when it's present. Relative paths need to stay relative; the domain will change when this moves to production.

With the user side stable, the week shifted to login. Sessions got added to the header, a sign-up page was created, and api-auth.php took its first shape. By end of week, both login and logout were working.

The Hard Part

The FormData type error on the login form consumed more time than it deserved. The form submission was failing in the browser console with an error about an invalid type being passed to FormData. Identical pattern to the working user profile form. The difference: login form elements had name attributes but not id attributes, and the code was using getElementById() for lookups. One missing attribute, one broken submit.

The git branch situation was stranger. Created a new branch to isolate the login work, came back to it later, and found that one file was empty and another was missing recent changes. No explanation surfaced. Eventually moved the work back to main and continued. It held fine. The uncertainty it left behind — not knowing what happened or whether it could happen again — was its own kind of uncomfortable.

Learnings

FormData lookups by element ID require actual id attributes, not just name attributes. The two look identical in HTML at a glance. Worth checking first when a FormData call that should work doesn't.

Next Week

Login and logout work. Session regeneration on login is still outstanding, and the login check that gates the rest of the app hasn't been added to the header yet. Those are the two remaining pieces before auth is properly in place.