stuff #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Executive Summary
This PR refactors the authentication flow by extracting JWT middleware into a dedicated
middleware/auth.gopackage, introduces a new social profiles feature with corresponding database migrations, handlers, and queries, and improves route organization using Echo's group middleware. It also upgrades database dependencies, standardizes SQL formatting, and fixes a historical response typo in collection creation.Critical Issues (High Priority)
services/users.go: The lineHasLoggedIn: *db_user.HasLoggedIn,directly dereferences a*boolfrom the database. If thehas_logged_incolumn isNULL, this will cause a runtime panic.HandlePostUserSocialandHandleDeleteUserSocial, database errors are returned ashttp.StatusNotFound(404). A 404 semantically means the requested resource doesn't exist, but these are write/delete operations failing. This misleads clients and breaks standard API conventions.HandleGetUserSocialsbypasses the new centralized parsing logic by callingutils.ParseInt(c.Param("userId"))directly, while other handlers usem.GetPathUserID(c). This breaks consistency and could cause subtle bugs if the parsing logic or error handling changes later.main.go,OptionalJWTruns globally, thenRequiredJWTruns on private groups. While functional,RequiredJWT'sSuccessHandlerwill overwrite the context value set byOptionalJWT. Consider explicitly chainingOptionalJWTonprivor using a single unified auth middleware to avoid redundant JWT parsing and context overwrites.c.String(http.StatusNotFound, "Error adding social...")withecho.NewHTTPErroror structured JSON responses. This improves client-side error parsing and aligns with modern REST conventions.valkey/valkeyindocker-compose.yamlis a good move for licensing, but add a comment incache/init.goordocker-compose.yamlconfirming thatgo-redis/v9is verified against Valkey 8.x to prevent future version mismatch surprises.migrations/20260426160059_dan.sql, the columndanis unquoted. While PostgreSQL accepts it, quoting identifiers ("dan" varchar(32)) is safer practice to avoid conflicts with reserved keywords in future releases.HandleGetUserSocials,HandlePostUserSocial,HandleDeleteUserSocial) lack unit tests. Adding tests for validation, success paths, and DB error handling will significantly improve reliability.services/users.goby safely handlingdb_user.HasLoggedIn(e.g., check for nil or use a helper likeutils.BoolPtrbefore dereferencing).HandlePostUserSocialandHandleDeleteUserSocialfromStatusNotFoundtoStatusInternalServerError(or map specific DB errors appropriately).HandleGetUserSocialsto usem.GetPathUserID(c)for consistency with other handlers.RequiredJWTmiddleware correctly handles context inheritance fromOptionalJWTand doesn't cause unexpected overwrites or redundant parsing.dancolumn name in20260426160059_dan.sqlmigration for safer SQL standard compliance.docker-compose.yamlorcache/init.gonoting the Redis-to-Valkey migration and confirmgo-redis/v9support.c.String()error responses withecho.NewHTTPErroror JSON payloads for consistent API error formatting.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.