package api import ( "net/http" "github.com/alchemistkay/guestguard/internal/domain" "github.com/alchemistkay/guestguard/internal/storage" ) type meHandler struct { users *storage.UserRepo } // GET /me — returns the authenticated user. Used by the frontend to bootstrap // after a page reload (with a fresh access token from /auth/refresh). func (h *meHandler) get(w http.ResponseWriter, r *http.Request) { uid, ok := UserIDFromContext(r.Context()) if !ok { writeError(w, http.StatusUnauthorized, "unauthenticated") return } u, err := h.users.GetByID(r.Context(), uid) if err != nil { if err == domain.ErrUserNotFound { writeError(w, http.StatusUnauthorized, "user not found") return } writeError(w, http.StatusInternalServerError, "failed to load user") return } writeJSON(w, http.StatusOK, u) }