mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-20 03:40:29 +05:00
Extend access token lifetime
This commit is contained in:
parent
7a803688de
commit
a1b648da91
|
@ -91,7 +91,7 @@ func AuthMiddleware(c *gin.Context, db *gorm.DB, cfg *config.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new token if the old one is about to expire
|
// Create a new token if the old one is about to expire
|
||||||
if time.Now().Add(12 * time.Hour).After(claims.ExpiresAt.Time) {
|
if time.Now().Add(time.Hour * 24 * 3).After(claims.ExpiresAt.Time) {
|
||||||
newToken, err := GetJWTToken(cfg)
|
newToken, err := GetJWTToken(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ShowError(c, err)
|
ShowError(c, err)
|
||||||
|
@ -103,7 +103,7 @@ func AuthMiddleware(c *gin.Context, db *gorm.DB, cfg *config.Config) {
|
||||||
|
|
||||||
func GetJWTToken(cfg *config.Config) (string, error) {
|
func GetJWTToken(cfg *config.Config) (string, error) {
|
||||||
claims := jwt.RegisteredClaims{
|
claims := jwt.RegisteredClaims{
|
||||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(24 * time.Hour)),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 7)),
|
||||||
}
|
}
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||||
return token.SignedString([]byte(cfg.SecretKey))
|
return token.SignedString([]byte(cfg.SecretKey))
|
||||||
|
|
Loading…
Reference in a new issue