add CacheService.findLocalUserByNativeToken and findOptionalLocalUserByNativeToken
This commit is contained in:
parent
8bf15a7fc2
commit
1eb7159173
2 changed files with 15 additions and 2 deletions
|
|
@ -701,6 +701,20 @@ export class CacheService implements OnApplicationShutdown {
|
|||
return user;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async findLocalUserByNativeToken(token: string): Promise<MiLocalUser> {
|
||||
const id = await this.nativeTokenCache.fetch(token);
|
||||
return await this.findLocalUserById(id);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async findOptionalLocalUserByNativeToken(token: string): Promise<MiLocalUser | undefined> {
|
||||
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<MiRemoteUser> {
|
||||
const user = await this.findUserById(userId);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue