Files
doormile_backend/middlewares/internal_auth.go
Suriya c91c887726 Add assignment engine, FCM, WebSockets, city gate, and internal APIs
- internal/assignment: GEORADIUS miler assignment with retry/escalation,
  customer-side provider scoring, FCM notifications on assign
- internal/notify: Firebase Admin SDK (FCM) client initialisation
- internal/ws: WebSocket handlers for live parcel tracking and
  customer↔miler chat
- middlewares: city gate (pincode prefix validation), internal API key
  auth, WebSocket JWT auth
- controllers: InternalNotify + InternalReassign for machine-to-machine
  calls; pricing helpers wired into CreateCustomerBooking and CreateCRMBooking
- routes: /internal/*, /ws/bookings/:id/track, /ws/bookings/:id/chat
- models/users, models/doormile_pricing: new fields for device tokens,
  assignment state, pricing bands
- seed_data.sql: initial pricing seed rows

.env and Firebase service-account JSON intentionally excluded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 12:31:53 +05:30

22 lines
591 B
Go

package middlewares
import (
"os"
"github.com/gofiber/fiber/v2"
)
// InternalKeyAuth guards machine-to-machine endpoints with a static API key.
// The key is read from INTERNAL_API_KEY env var at request time so it can be
// rotated without redeployment. Returns 401 if the header is missing or wrong.
func InternalKeyAuth(c *fiber.Ctx) error {
expected := os.Getenv("INTERNAL_API_KEY")
if expected == "" || c.Get("X-Internal-Key") != expected {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"success": false,
"message": "unauthorized",
})
}
return c.Next()
}