forked from EvolutionAPI/evolution-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.service.ts
More file actions
24 lines (19 loc) · 716 Bytes
/
auth.service.ts
File metadata and controls
24 lines (19 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { PrismaRepository } from '@api/repository/repository.service';
import { BadRequestException } from '@exceptions';
export class AuthService {
constructor(private readonly prismaRepository: PrismaRepository) {}
public async checkDuplicateToken(token: string) {
if (!token) {
return true;
}
// Compara apenas os primeiros 255 caracteres para verificar duplicatas
const tokenToCompare = token.length > 255 ? token.substring(0, 255) : token;
const instances = await this.prismaRepository.instance.findMany({
where: { token: tokenToCompare },
});
if (instances.length > 0) {
throw new BadRequestException('Token already exists');
}
return true;
}
}