Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old tokens not being deleted #1183

Open
kaustubh-nair opened this issue Jun 26, 2018 · 2 comments
Open

Old tokens not being deleted #1183

kaustubh-nair opened this issue Jun 26, 2018 · 2 comments

Comments

@kaustubh-nair
Copy link

  • Version: 0.1.43

I currently have config.max_number_of_devices = 6 and config.token_lifespan = 10.weeks but everytime I login it is creating a new token and not deleting the older ones. As a result I have 63 tokens right now which I verified by running User.first.tokens.count
Is there a way to delete old tokens?

@dks17
Copy link
Contributor

dks17 commented Sep 12, 2018

@KauNair, hello.
Let's take a look here:

def remove_tokens_after_password_reset
return unless should_remove_tokens_after_password_reset?
if tokens.present? && tokens.many?
client_id, token_data = tokens.max_by { |cid, v| v[:expiry] || v['expiry'] }
self.tokens = { client_id => token_data }
end
end

  1. Set remove_tokens_after_password_reset = true in the gem initialize file.
  2. Call User.first.remove_tokens_after_password_reset where you want.
  3. Or implement if block from remove_tokens_after_password_reset where you need.

Or the second way:

user = User.first
user.tokens = {}
user.save

I didn't check these ways, but you should try them.

@bananatron
Copy link
Contributor

bananatron commented Sep 20, 2018

It looks like this should be handling it:

before_save :destroy_expired_tokens

def destroy_expired_tokens
if tokens
tokens.delete_if do |cid, v|
expiry = v[:expiry] || v['expiry']
DateTime.strptime(expiry.to_s, '%s') < Time.zone.now
end
end
end

Might be worth looking at the actual expiry and your server time and seeing if it actually meets these conditions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants