From 1eb71591735145f80cb47316994ca776a07468a0 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Mon, 6 Oct 2025 12:03:19 -0400 Subject: [PATCH] add CacheService.findLocalUserByNativeToken and findOptionalLocalUserByNativeToken --- packages/backend/src/core/CacheService.ts | 14 ++++++++++++++ .../backend/src/server/api/AuthenticateService.ts | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index 30c313cbf1..3c86be78de 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -701,6 +701,20 @@ export class CacheService implements OnApplicationShutdown { return user; } + @bindThis + public async findLocalUserByNativeToken(token: string): Promise { + const id = await this.nativeTokenCache.fetch(token); + return await this.findLocalUserById(id); + } + + @bindThis + public async findOptionalLocalUserByNativeToken(token: string): Promise { + const id = await this.nativeTokenCache.fetchMaybe(token); + if (id == null) return undefined; + + return await this.findOptionalLocalUserById(id); + } + @bindThis public async findRemoteUserById(userId: MiUser['id']): Promise { const user = await this.findUserById(userId); diff --git a/packages/backend/src/server/api/AuthenticateService.ts b/packages/backend/src/server/api/AuthenticateService.ts index ab8bf1522e..f9bccb638e 100644 --- a/packages/backend/src/server/api/AuthenticateService.ts +++ b/packages/backend/src/server/api/AuthenticateService.ts @@ -53,8 +53,7 @@ export class AuthenticateService { } if (isNativeUserToken(token)) { - const userId = await this.cacheService.nativeTokenCache.fetch(token); - const user = userId ? await this.cacheService.findLocalUserById(userId) : null; + const user = await this.cacheService.findOptionalLocalUserByNativeToken(token); if (user == null) { throw new AuthenticationError('user not found');