|
|
@ -32,12 +32,12 @@ export class ApiKeyService { |
|
|
public async getUserByApiKey(apiKey: string) { |
|
|
public async getUserByApiKey(apiKey: string) { |
|
|
const hashedKey = this.hashApiKey(apiKey); |
|
|
const hashedKey = this.hashApiKey(apiKey); |
|
|
|
|
|
|
|
|
const { user } = await this.prismaService.apiKey.findUnique({ |
|
|
const apiKeyFromDatabase = await this.prismaService.apiKey.findUnique({ |
|
|
include: { user: true }, |
|
|
include: { user: true }, |
|
|
where: { hashedKey } |
|
|
where: { hashedKey } |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return user; |
|
|
return apiKeyFromDatabase?.user; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public hashApiKey(apiKey: string): string { |
|
|
public hashApiKey(apiKey: string): string { |
|
|
@ -53,7 +53,7 @@ export class ApiKeyService { |
|
|
private generateApiKey(): string { |
|
|
private generateApiKey(): string { |
|
|
return getRandomString(32) |
|
|
return getRandomString(32) |
|
|
.split('') |
|
|
.split('') |
|
|
.reduce((acc, char, index) => { |
|
|
.reduce<string[]>((acc, char, index) => { |
|
|
const chunkIndex = Math.floor(index / 4); |
|
|
const chunkIndex = Math.floor(index / 4); |
|
|
acc[chunkIndex] = (acc[chunkIndex] || '') + char; |
|
|
acc[chunkIndex] = (acc[chunkIndex] || '') + char; |
|
|
return acc; |
|
|
return acc; |
|
|
|