feat: switch to global auth and tenant route prefix

This commit is contained in:
2026-01-26 18:04:05 +08:00
parent 8addf6f900
commit cde4fb8594
25 changed files with 479 additions and 7196 deletions

View File

@@ -3,8 +3,6 @@ package auth
import (
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/services"
"quyun/v2/database/models"
"quyun/v2/pkg/consts"
"github.com/gofiber/fiber/v3"
)
@@ -14,7 +12,7 @@ type Auth struct{}
// SendOTP sends an OTP to the provided phone number.
//
// @Router /t/:tenantCode/v1/auth/otp [post]
// @Router /v1/auth/otp [post]
// @Summary Send OTP
// @Description Send OTP to phone number
// @Tags Auth
@@ -27,9 +25,7 @@ func (a *Auth) SendOTP(ctx fiber.Ctx, form *dto.SendOTPForm) error {
return services.User.SendOTP(ctx, form.Phone)
}
// Login logs in or registers a user with OTP.
//
// @Router /t/:tenantCode/v1/auth/login [post]
// @Router /v1/auth/login [post]
// @Summary Login or Register with OTP
// @Description Login or register user using phone number and OTP
// @Tags Auth
@@ -39,11 +35,5 @@ func (a *Auth) SendOTP(ctx fiber.Ctx, form *dto.SendOTPForm) error {
// @Success 200 {object} dto.LoginResponse
// @Bind form body
func (a *Auth) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
tenantID := int64(0)
if t := ctx.Locals(consts.CtxKeyTenant); t != nil {
if tenant, ok := t.(*models.Tenant); ok {
tenantID = tenant.ID
}
}
return services.User.LoginWithOTP(ctx, tenantID, form.Phone, form.OTP)
return services.User.LoginWithOTP(ctx, 0, form.Phone, form.OTP)
}

View File

@@ -42,13 +42,13 @@ func (r *Routes) Name() string {
// Each route is registered with its corresponding controller action and parameter bindings.
func (r *Routes) Register(router fiber.Router) {
// Register routes for controller: Auth
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/auth/login -> auth.Login")
router.Post("/t/:tenantCode/v1/auth/login"[len(r.Path()):], DataFunc1(
r.log.Debugf("Registering route: Post /v1/auth/login -> auth.Login")
router.Post("/v1/auth/login"[len(r.Path()):], DataFunc1(
r.auth.Login,
Body[dto.LoginForm]("form"),
))
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/auth/otp -> auth.SendOTP")
router.Post("/t/:tenantCode/v1/auth/otp"[len(r.Path()):], Func1(
r.log.Debugf("Registering route: Post /v1/auth/otp -> auth.SendOTP")
router.Post("/v1/auth/otp"[len(r.Path()):], Func1(
r.auth.SendOTP,
Body[dto.SendOTPForm]("form"),
))

View File

@@ -1,11 +1,9 @@
package auth
func (r *Routes) Path() string {
return "/t/:tenantCode/v1/auth"
return "/v1/auth"
}
func (r *Routes) Middlewares() []any {
return []any{
r.middlewares.TenantResolver,
}
return []any{}
}