You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docuseal/lib/auth_with_token_strategy.rb

22 lines
435 B

# frozen_string_literal: true
class AuthWithTokenStrategy < Devise::Strategies::Base
def valid?
request.headers['X-Auth-Token'].present?
end
def authenticate!
payload = JsonWebToken.decode(request.headers['X-Auth-Token'])
user = User.find_by(uuid: payload['uuid'])
if user
success!(user)
else
fail!('Invalid token')
end
rescue JWT::VerificationError
fail!('Invalid token')
end
end