Skip to content

Commit 8aa3a3c

Browse files
committed
Always ensure the newly created token expiry is not behind from existing ones
1 parent b7fcfdf commit 8aa3a3c

File tree

1 file changed

+5
-2
lines changed
  • app/models/devise_token_auth/concerns

1 file changed

+5
-2
lines changed

app/models/devise_token_auth/concerns/user.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ def send_unlock_instructions(opts = {})
9292
def create_token(client: nil, lifespan: nil, cost: nil, **token_extras)
9393
token = DeviseTokenAuth::TokenFactory.create(client: client, lifespan: lifespan, cost: cost)
9494

95+
max_expiration_token = tokens.max_by { |_, token_info| token_info['expiry'] }
96+
max_expiry = max_expiration_token&.dig(1, 'expiry') || 0
97+
9598
tokens[token.client] = {
96-
token: token.token_hash,
97-
expiry: token.expiry
99+
token: token.token_hash,
100+
expiry: [token.expiry, max_expiry + 1].max
98101
}.merge!(token_extras)
99102

100103
clean_old_tokens

0 commit comments

Comments
 (0)