From caa4cd491ee7a396fcc4cd1dfb772c17afda37cf Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 2 Dec 2025 12:47:00 +0100 Subject: [PATCH] Smooth out the finder API --- app/controllers/concerns/authentication.rb | 4 ++-- app/models/identity.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb index b125ea550..510cac074 100644 --- a/app/controllers/concerns/authentication.rb +++ b/app/controllers/concerns/authentication.rb @@ -59,8 +59,8 @@ module Authentication authorization_scheme, bearer_token = request.authorization.to_s.split(" ", 2) if authorization_scheme == "Bearer" && bearer_token.present? - if access_token = Identity::AccessToken.find_by(token: bearer_token) - Current.identity = access_token.identity + if identity = Identity.find_by_access_token(bearer_token) + Current.identity = identity else head :unauthorized end diff --git a/app/models/identity.rb b/app/models/identity.rb index f6dd7d433..43466bd30 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -14,6 +14,10 @@ class Identity < ApplicationRecord validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP } normalizes :email_address, with: ->(value) { value.strip.downcase.presence } + def self.find_by_access_token(token) + AccessToken.find_by(token: token)&.identity + end + def send_magic_link(**attributes) attributes[:purpose] = attributes.delete(:for) if attributes.key?(:for)