From d5f3f5e783c81a9a969990618bd3315fb4ba3bfd Mon Sep 17 00:00:00 2001 From: Preston Baxter Date: Sun, 29 Oct 2023 17:56:05 -0500 Subject: [PATCH] B: Make auth middleware redirect to login when token is invalid --- ui/controllers/auth_middleware.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ui/controllers/auth_middleware.go b/ui/controllers/auth_middleware.go index 1595007..347e675 100644 --- a/ui/controllers/auth_middleware.go +++ b/ui/controllers/auth_middleware.go @@ -71,15 +71,23 @@ func AuthMiddleware(strict bool) gin.HandlerFunc { return []byte(conf.JwtSecret), nil }) if err != nil { - if err == jwt.ErrSignatureInvalid { - log.Warn("Redirecting, jwt invalid") + if err == jwt.ErrTokenExpired{ + log.Warn("Redirecting, jwt expired") c.Redirect(301, "/login") return + }else{ + if strict { + log.Warnf("Redirecting, jwt issue: %s", err) + c.Redirect(301, "/login") + return + } else { + log.Warnf("Jwt is invalid, but auth is not strict. Reason: %s", err) + return + } } - log.WithError(err).Error("Unable to get cookie from browser") - c.AbortWithError(504, err) - return } + + if !parsedToken.Valid { if strict { log.Warn("Redirecting, jwt invalid")