From 55bc7f70d1bc74cf22df6f55f1c9fe2bce9151fa Mon Sep 17 00:00:00 2001 From: Suriyakumarvijayanayagam Date: Wed, 26 Aug 2026 17:05:06 +0530 Subject: [PATCH] feat: expose tenantname on miler verify-pin and profile responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The miler app resolves a rider's service profile (hyperlocal vs logistics, which decides whether the Start-delivery button renders) from the tenant NAME in preference to the raw tenantid. Neither verify-pin nor GET /miler/profile returned a tenant name — the field the app keys off did not exist. Add resolveTenantName and include tenantname (+ tenantid) on both responses. Including it on GET /miler/profile lets the app refresh tenantname at launch without forcing a re-login after this rollout. This is the precondition for safely enabling MILER_COLLECTED_STATE_ENABLED: without tenantname, any tenant whose id the app hasn't mapped falls back to the logistics profile (no Start-delivery button) and would strand collected hyperlocal parcels. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD --- controllers/milerController.go | 54 ++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/controllers/milerController.go b/controllers/milerController.go index 6e1f11e..0c745d6 100644 --- a/controllers/milerController.go +++ b/controllers/milerController.go @@ -68,6 +68,23 @@ func LoginMiler(cfg *config.Config) fiber.Handler { } } +// resolveTenantName returns the tenant's display name for a tenantid, or "" +// when the id is unset/unknown. The miler app resolves a rider's service +// profile (hyperlocal vs logistics) from this name in preference to the raw +// tenantid, so it must be present on the login and profile responses — a rider +// whose tenant we don't name falls back to id-matching, and any unmapped id +// falls back to logistics (no Start-delivery button). Cheap single-row lookup. +func resolveTenantName(tenantID int) string { + if tenantID == 0 { + return "" + } + var t models.Tenant + if err := db.DB.Select("tenantname").Where("tenantid = ?", tenantID).First(&t).Error; err != nil { + return "" + } + return t.Tenantname +} + func VerifyMilerPin(cfg *config.Config) fiber.Handler { return func(c *fiber.Ctx) error { req := new(dto.MilerPinVerifyRequest) @@ -123,15 +140,24 @@ func VerifyMilerPin(cfg *config.Config) fiber.Handler { db.DB.Model(&profile).Update("device_token", req.DeviceToken) } + // tenantname drives the app's service-profile resolution (hyperlocal vs + // logistics), checked ahead of the raw tenantid. Persisted client-side at + // verify-pin, so a rider picks up a changed tenant name on next login. + tenantName := resolveTenantName(user.Tenantid) + return c.JSON(fiber.Map{ - "success": true, - "token": token, + "success": true, + "token": token, + "tenantid": user.Tenantid, + "tenantname": tenantName, "user": fiber.Map{ - "userid": user.Userid, - "authname": user.Authname, - "email": user.Email, - "contactno": user.Contactno, - "profile": profile, + "userid": user.Userid, + "authname": user.Authname, + "email": user.Email, + "contactno": user.Contactno, + "tenantid": user.Tenantid, + "tenantname": tenantName, + "profile": profile, }, }) } @@ -192,12 +218,16 @@ func GetMilerProfile(c *fiber.Ctx) error { return utils.NotFound(c, "miler profile not found") } + // tenantname is included here too so the app can refresh it at launch via + // GET /miler/profile without forcing a re-login after the tenantname rollout. return utils.OK(c, fiber.Map{ - "userid": user.Userid, - "authname": user.Authname, - "email": user.Email, - "contactno": user.Contactno, - "profile": profile, + "userid": user.Userid, + "authname": user.Authname, + "email": user.Email, + "contactno": user.Contactno, + "tenantid": user.Tenantid, + "tenantname": resolveTenantName(user.Tenantid), + "profile": profile, }) }