fix(auth): match OIDC users by their sub claim so an email change still logs in

Store the provider's `sub` on a new nullable users.oidc_sub column, look users
up by it first and fall back to email, backfilling the sub on the next login. A
user matched by sub gets their stored email updated, unless another account
already holds it.

Fixes #1690

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-09-28 14:40:22 -04:00
committed by GitHub
parent de0eff320c
commit 9d4bb40a6d
7 changed files with 208 additions and 15 deletions

View File

@@ -64,6 +64,14 @@ class DBUsersHandler(DBBaseHandler):
query = self.filter(select(User), emails=[email])
return session.scalar(query.limit(1))
@begin_session
def get_user_by_oidc_sub(
self,
oidc_sub: str,
session: Session = INJECTED_SESSION,
) -> User | None:
return session.scalar(select(User).filter_by(oidc_sub=oidc_sub).limit(1))
@begin_session
def get_user(
self,