feat(middleware): add GetAccountID by jwtToken

This commit is contained in:
Leon
2025-12-09 15:27:33 +08:00
parent 5c79e99b70
commit 72f35f7a7a

View File

@@ -2,6 +2,7 @@
package middleware
import (
"errors"
"net/http"
"strings"
@@ -46,3 +47,17 @@ func JWTAuth(accountRepo *account.AccountRepository) gin.HandlerFunc {
c.Next()
}
}
func GetAccountID(c *gin.Context) (uint, error) {
uidValue, exists := c.Get("accountID")
if !exists {
return 0, errors.New("accountID not found")
}
accountID, ok := uidValue.(uint)
if !ok {
return 0, errors.New("accountID has invalid type")
}
return accountID, nil
}