Skip to content

Commit 6a4718e

Browse files
authored
Fixed an issue where private key was loaded before main code (#62)
1 parent df24354 commit 6a4718e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

auth/auth.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/google/uuid"
1010
)
1111

12-
var jwtKey = config.GetPrivateKey(1)
13-
1412
type JWTClaim struct {
1513
Firstname string `json:"first_name"`
1614
Lastname string `json:"last_name"`
@@ -38,17 +36,20 @@ func GenerateJWT(firstname string, lastname string, email string, userid uuid.UU
3836
},
3937
}
4038
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
39+
jwtKey := config.GetPrivateKey(1)
4140
tokenString, err = token.SignedString(jwtKey)
4241
return
4342
}
4443

4544
func GenerateJWTFromClaims(claims *JWTClaim) (tokenString string, err error) {
4645
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
46+
jwtKey := config.GetPrivateKey(1)
4747
tokenString, err = token.SignedString(jwtKey)
4848
return
4949
}
5050

5151
func ValidateToken(signedToken string, admin bool) (err error) {
52+
jwtKey := config.GetPrivateKey(1)
5253
token, err := jwt.ParseWithClaims(
5354
signedToken,
5455
&JWTClaim{},
@@ -84,6 +85,7 @@ func ValidateToken(signedToken string, admin bool) (err error) {
8485
}
8586

8687
func ParseToken(signedToken string) (*JWTClaim, error) {
88+
jwtKey := config.GetPrivateKey(1)
8789
token, err := jwt.ParseWithClaims(
8890
signedToken,
8991
&JWTClaim{},

0 commit comments

Comments
 (0)