feat: 添加用户注册功能,包括表单验证和路由注册
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user