Repository navigation
Fix frontend integration spoted lapse - #4
Conversation
peterintech
commented
Sep 4, 2026
- fix: improve erorr handling
- refactor: move frontend to its own repo to deploy seperate
- fix(api): align authentication and CORS behavior
- fix(posts): use authenticated actors and expose authors
- feat(users): add private profiles and relationship status
- feat(mailer): add configurable SMTP delivery
- test(mailer): cover SMTP and registration delivery
- docs(config): add mail provider environment example
There was a problem hiding this comment.
🟡 Changes recommended
There are a few correctness/security issues in the updated mail delivery and auth/token behavior that can cause silent email failures and enable user enumeration unless addressed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR removes the in-repo Vite/React frontend (consistent with “move frontend to its own repo”) and focuses the backend on improved auth-aligned behavior and richer user/post interactions, plus a refactor of mail delivery to support both SendGrid and SMTP with tests and config examples.
Changes:
- Removed the
web/Vite/React frontend scaffolding and assets. - Refactored the mailer into a provider-agnostic interface, added an SMTP mailer implementation, and added unit + opt-in integration tests.
- Updated API/store behavior around authenticated actors (feeds/comments), relationship status, and post author exposure; plus improved duplicate user detection and CORS defaults.
File summaries
| File | Description |
|---|---|
| web/vite.config.js | Removed frontend build config as part of frontend repo split. |
| web/src/main.jsx | Removed frontend entrypoint/router. |
| web/src/lib/utils.js | Removed frontend utility module. |
| web/src/ConfirmationPage.jsx | Removed frontend confirmation page. |
| web/src/components/ui/button.jsx | Removed frontend UI component. |
| web/src/assets/vite.svg | Removed frontend asset. |
| web/src/assets/react.svg | Removed frontend asset. |
| web/src/App.jsx | Removed frontend app component. |
| web/src/App.css | Removed frontend styling. |
| web/README.md | Removed frontend template README. |
| web/public/icons.svg | Removed frontend icons sprite. |
| web/public/favicon.svg | Removed frontend favicon. |
| web/package.json | Removed frontend package manifest. |
| web/jsconfig.json | Removed frontend JS tooling config. |
| web/index.html | Removed frontend HTML entrypoint. |
| web/components.json | Removed shadcn/ui config. |
| web/.oxlintrc.json | Removed frontend lint config. |
| web/.gitignore | Removed frontend gitignore. |
| internal/store/users.go | Improved duplicate user detection using pq.Error metadata. |
| internal/store/storage.go | Updated duplicate error messages; extended Followers store interface with IsFollowing. |
| internal/store/posts.go | Joined users on post fetch and began populating author data. |
| internal/store/followers.go | Added IsFollowing query helper. |
| internal/mailer/templates/user_invitation.tmpl | Fixed malformed HTML in the welcome/invitation template. |
| internal/mailer/smtp.go | Added SMTP mailer implementation with retries and message building. |
| internal/mailer/smtp_test.go | Added SMTP unit tests (message shape, retries, cancellation, injection). |
| internal/mailer/smtp_integration_test.go | Added opt-in SMTP integration test gated by env var. |
| internal/mailer/sendgrid.go | Refactored SendGrid mailer to use shared template renderer and context-aware retries. |
| internal/mailer/renderer.go | Added shared HTML template renderer (subject/body) using html/template. |
| internal/mailer/mailer.go | Refactored mailer interface to Send(ctx, ...) error. |
| internal/mailer/mailer_test.go | Added tests for template rendering + HTML escaping. |
| cmd/api/users.go | Added public profile response shaping + “me” and relationship endpoints. |
| cmd/api/main.go | Added mail provider selection + SMTP config and centralized mailer construction. |
| cmd/api/mailer.go | Added resolveNewMailer helper for provider selection. |
| cmd/api/mailer_test.go | Added tests for provider resolution. |
| cmd/api/feeds.go | Fixed feed lookup to use the authenticated user ID (removed hardcoded ID). |
| cmd/api/comments.go | Fixed comment creation to attribute the authenticated actor as author. |
| cmd/api/auth.go | Updated activation URL joining and switched mail sending to new interface; altered token endpoint error mapping. |
| cmd/api/auth_test.go | Added registration rollback test coverage around mail delivery failures. |
| cmd/api/api.go | Added mail config struct fields; adjusted CORS defaults/methods; added new user routes. |
| .env.example | Added environment example including mail provider + SMTP settings. |
Review details
Suppressed comments (1)
cmd/api/auth.go:160
- This login endpoint currently returns 404 when the email isn’t found, but the swagger docs declare a 401 and returning 404 enables user enumeration by distinguishing “unknown email” vs “wrong password”. Prefer a single 401 response for invalid credentials (and keep the detailed error only for logs).
user, err := app.store.Users.GetByEmail(r.Context(), payload.Email)
if err != nil {
switch err {
case store.ErrNotFound:
app.notFoundError(w, r, err)
default:
app.internalServerError(w, r, err)
}
return
- Files reviewed: 36/42 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if cfg.FromName == "" { | ||
| return nil, fmt.Errorf("MAIL_FROM_NAME is required") | ||
| } | ||
| if err := validateAddress(cfg.FromEmail); err != nil { | ||
| return nil, fmt.Errorf("invalid MAIL_FROM_EMAIL: %w", err) | ||
| } |
| for i := range maxRetries { | ||
| res, retryErr := s.client.Send(message) | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, retryErr = s.client.Send(message) | ||
| if retryErr != nil { |
| post := &Post{User: &User{}} | ||
| err := s.db.QueryRowContext(ctx, query, postID).Scan(&post.ID, &post.Content, &post.Title, pq.Array(&post.Tags), &post.Version, &post.UserID, &post.CreatedAt, &post.UpdatedAt, &post.User.Username) | ||
|
|
There was a problem hiding this comment.
🟡 Changes recommended
The token endpoint now returns 404 for unknown emails (enabling account enumeration) and a relationship handler path ignores JSON response errors, both of which should be corrected before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Files not reviewed (1)
- docs/docs.go: Generated file
Suppressed comments (1)
.env.example:12
- .env.example REDIS_ADDR uses host port 6379, but docker-compose.yml publishes Redis on 6380; the example should match the compose file's host port mapping.
REDIS_ADDR=localhost:6379
- Files reviewed: 43/50 changed files
- Comments generated: 4
- Review effort level: Lite
| case store.ErrNotFound: | ||
| app.unauthorizedError(w, r, err) | ||
| app.notFoundError(w, r, err) | ||
| default: | ||
| app.internalServerError(w, r, err) | ||
| } |
| if viewer.ID == targetID { | ||
| _ = app.jsonResponse(w, http.StatusOK, relationshipResponse{IsFollowing: false}) | ||
| return | ||
| } |
| FRONTEND_URL=http://localhost:5173/ | ||
| CORS_ALLOWED_ORIGIN=http://localhost:5173 | ||
|
|
||
| DB_ADDR=postgres://postgres:postgres@localhost:5432/psocial?sslmode=disable |
| ### 2. Configure the application | ||
|
|
||
| ```powershell | ||
| .env.example .env |