feat: 添加用户注册功能,包括表单验证和路由注册

This commit is contained in:
2025-12-24 22:46:50 +08:00
parent 7a03ba3a00
commit fd9e54e9f4
7 changed files with 240 additions and 6 deletions

View File

@@ -10,17 +10,24 @@ import (
"github.com/gofiber/fiber/v3"
)
func shouldSkipUserJWTAuth(path string) bool {
// 登录接口无需鉴权
if strings.Contains(path, "/v1/auth/login") {
return true
func shouldSkipUserJWTAuth(path string, method string) bool {
// 仅对明确的公开接口放行,避免误伤其它路径
if method != fiber.MethodPost {
return false
}
p := strings.TrimSuffix(path, "/")
switch p {
case "/v1/auth/login", "/v1/auth/register":
return true
default:
return false
}
return false
}
// UserAuth 为平台通用(非租户域)接口提供 JWT 校验,并写入 claims 到 ctx locals。
func (f *Middlewares) UserAuth(c fiber.Ctx) error {
if shouldSkipUserJWTAuth(c.Path()) {
if shouldSkipUserJWTAuth(c.Path(), c.Method()) {
f.log.Debug("middlewares.user.auth.skipped")
return c.Next()
}