feat: update

This commit is contained in:
Rogee
2025-04-30 18:50:11 +08:00
parent 42c1c17c0a
commit 11288471d4
8 changed files with 204 additions and 91 deletions

View File

@@ -3,6 +3,7 @@ package middlewares
import (
"net/url"
"strings"
"time"
"quyun/app/models"
"quyun/pkg/utils"
@@ -70,6 +71,17 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
}
return ctx.Redirect().To(fullUrl)
}
// TOKEN 过期
if user.AuthToken.Data.ExpiresAt.Before(time.Now()) {
// remove cookie
ctx.ClearCookie("token")
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}
return ctx.Redirect().To(fullUrl)
}
ctx.Locals("user", user)
return ctx.Next()