fix: improve error handling and session management in various handlers and middleware

This commit is contained in:
GitHub Actions
2026-02-14 00:51:40 +00:00
parent c7d013c503
commit f906f4a21f
6 changed files with 139 additions and 60 deletions

View File

@@ -323,17 +323,15 @@ func (h *AuthHandler) ChangePassword(c *gin.Context) {
func (h *AuthHandler) Verify(c *gin.Context) {
// Extract token from cookie or Authorization header
var tokenString string
// Try cookie first (most common for browser requests)
if cookie, err := c.Cookie("auth_token"); err == nil && cookie != "" {
tokenString = cookie
authHeader := c.GetHeader("Authorization")
if strings.HasPrefix(authHeader, "Bearer ") {
tokenString = strings.TrimPrefix(authHeader, "Bearer ")
}
// Fall back to Authorization header
// Fall back to cookie (most common for browser requests)
if tokenString == "" {
authHeader := c.GetHeader("Authorization")
if strings.HasPrefix(authHeader, "Bearer ") {
tokenString = strings.TrimPrefix(authHeader, "Bearer ")
if cookie, err := c.Cookie("auth_token"); err == nil && cookie != "" {
tokenString = cookie
}
}
@@ -393,15 +391,14 @@ func (h *AuthHandler) Verify(c *gin.Context) {
func (h *AuthHandler) VerifyStatus(c *gin.Context) {
// Extract token
var tokenString string
if cookie, err := c.Cookie("auth_token"); err == nil && cookie != "" {
tokenString = cookie
authHeader := c.GetHeader("Authorization")
if strings.HasPrefix(authHeader, "Bearer ") {
tokenString = strings.TrimPrefix(authHeader, "Bearer ")
}
if tokenString == "" {
authHeader := c.GetHeader("Authorization")
if strings.HasPrefix(authHeader, "Bearer ") {
tokenString = strings.TrimPrefix(authHeader, "Bearer ")
if cookie, err := c.Cookie("auth_token"); err == nil && cookie != "" {
tokenString = cookie
}
}