Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d719dd9

Browse files
committedMay 22, 2025
fix(jwt): update GenerateAccessToken to return expiration time
1 parent fc930e8 commit d719dd9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎pkg/jwt/generate_token.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// JwtCustomClaims represents the custom claims for JWT with durationTime in Minuates
12-
func (j *jwtConfig) GenerateAccessToken(c context.Context, user *domain.User, durationTokenInMinuates int) (*string, error) {
12+
func (j *jwtConfig) GenerateAccessToken(c context.Context, user *domain.User, durationTokenInMinuates int) (*string, time.Time, error) {
1313
expiredTime := time.Now().Local().Add(time.Duration(durationTokenInMinuates) * time.Minute)
1414

1515
claims := JwtCustomClaims{
@@ -24,8 +24,8 @@ func (j *jwtConfig) GenerateAccessToken(c context.Context, user *domain.User, du
2424

2525
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
2626
if encodedToken, err := token.SignedString([]byte(j.SecretKey)); err != nil {
27-
return nil, err
27+
return nil, time.Time{}, err
2828
} else {
29-
return &encodedToken, err
29+
return &encodedToken, expiredTime, err
3030
}
3131
}

‎pkg/jwt/jwt.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package jwt
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/golang-jwt/jwt/v5"
78
"github.com/hammer-code/lms-be/domain"
@@ -22,7 +23,7 @@ type (
2223

2324
JWT interface {
2425
//GenerateAccessToken generates a new access token for the user with the given expiration time in minutes
25-
GenerateAccessToken(c context.Context, user *domain.User, expiredTimeInMinuate int) (*string, error)
26+
GenerateAccessToken(c context.Context, user *domain.User, expiredTimeInMinuate int) (*string, time.Time, error)
2627
VerifyToken(token string) (*JwtCustomClaims, error)
2728
}
2829
)
@@ -31,4 +32,4 @@ func NewJwt(secretKey string) JWT {
3132
return &jwtConfig{
3233
SecretKey: secretKey,
3334
}
34-
}
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.