Skip to content

Commit

Permalink
Always ensure the newly created token expiry is not behind from exist…
Browse files Browse the repository at this point in the history
…ing ones
  • Loading branch information
javaharut committed Jan 6, 2025
1 parent b7fcfdf commit 8aa3a3c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/devise_token_auth/concerns/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ def send_unlock_instructions(opts = {})
def create_token(client: nil, lifespan: nil, cost: nil, **token_extras)
token = DeviseTokenAuth::TokenFactory.create(client: client, lifespan: lifespan, cost: cost)

max_expiration_token = tokens.max_by { |_, token_info| token_info['expiry'] }
max_expiry = max_expiration_token&.dig(1, 'expiry') || 0

tokens[token.client] = {
token: token.token_hash,
expiry: token.expiry
token: token.token_hash,
expiry: [token.expiry, max_expiry + 1].max
}.merge!(token_extras)

clean_old_tokens
Expand Down

0 comments on commit 8aa3a3c

Please sign in to comment.