refactor: api key repository (#15491)

This commit is contained in:
Jason Rasmussen 2025-01-21 11:45:59 -05:00 committed by GitHub
parent 1745f48f3d
commit 9a1068c867
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 44 additions and 72 deletions

View file

@ -21,6 +21,7 @@ import { UserEntity } from 'src/entities/user.entity';
import { AuthType, ImmichCookie, ImmichHeader, ImmichQuery, Permission } from 'src/enum';
import { OAuthProfile } from 'src/interfaces/oauth.interface';
import { BaseService } from 'src/services/base.service';
import { AuthApiKey } from 'src/types';
import { isGranted } from 'src/utils/access';
import { HumanReadableSize } from 'src/utils/bytes';
@ -309,7 +310,10 @@ export class AuthService extends BaseService {
const hashedKey = this.cryptoRepository.hashSha256(key);
const apiKey = await this.keyRepository.getKey(hashedKey);
if (apiKey) {
return { user: apiKey.user, apiKey };
return {
user: apiKey.user as unknown as UserEntity,
apiKey: apiKey as unknown as AuthApiKey,
};
}
throw new UnauthorizedException('Invalid API key');