Fix grabage codes 5 years ago

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-23 23:46:00 +08:00
parent b933522123
commit 485d0de64b
8 changed files with 21 additions and 44 deletions

View File

@@ -2,13 +2,13 @@ package jwt
import (
"net/http"
"nixcn-cms/config"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/spf13/viper"
)
type Claims struct {
@@ -17,7 +17,7 @@ type Claims struct {
}
func JWTAuth() gin.HandlerFunc {
var JwtSecret = []byte(config.Get("server.jwt_secret").(string))
var JwtSecret = []byte(viper.GetString("server.jwt_secret"))
return func(c *gin.Context) {
auth := c.GetHeader("Authorization")
if auth == "" {
@@ -62,7 +62,7 @@ func JWTAuth() gin.HandlerFunc {
}
func GenerateToken(userID uuid.UUID, application string) (string, error) {
var JwtSecret = []byte(config.Get("server.jwt_secret").(string))
var JwtSecret = []byte(viper.GetString("server.jwt_secret"))
claims := Claims{
UserID: userID,
RegisteredClaims: jwt.RegisteredClaims{