Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created June 9, 2018 23:28
Show Gist options
  • Save jordanhudgens/afa5bbd136674c65f1873d97cbc42c64 to your computer and use it in GitHub Desktop.
Save jordanhudgens/afa5bbd136674c65f1873d97cbc42c64 to your computer and use it in GitHub Desktop.
module AuthTokenConcern
extend ActiveSupport::Concern
included do
before_action :unique_auth_token
end
def unique_auth_token
unique_auth = false
while unique_auth == false
auth_key = SecureRandom.base64.tr('+/=', 'Qrt')
if !User.all.where(auth_token: auth_key).any?
unique_auth = true
return auth_key
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment