feat: update

This commit is contained in:
yanghao05
2025-04-29 20:57:56 +08:00
parent 029ff4d84a
commit dd702a5bee
2 changed files with 17 additions and 6 deletions

View File

@@ -29,11 +29,6 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
return ctx.Next()
}
// check is XMLHttpRequest
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}
fullUrl := utils.FullURI(ctx)
u, err := url.Parse(fullUrl)
if err != nil {
@@ -50,6 +45,9 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
log.Infof("cookie: %s", cookie)
if cookie == "" {
log.Infof("auth redirect_uri: %s", fullUrl)
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}
return ctx.Redirect().To(fullUrl)
}
@@ -57,6 +55,9 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
if err != nil {
// remove cookie
ctx.ClearCookie("token")
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}
return ctx.Redirect().To(fullUrl)
}
@@ -64,6 +65,9 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
if err != nil {
// remove cookie
ctx.ClearCookie("token")
if ctx.XHR() {
return ctx.SendStatus(fiber.StatusUnauthorized)
}
return ctx.Redirect().To(fullUrl)
}
ctx.Locals("user", user)