2
0
Files
cal/calcom/apps/api/v2/test/mocks/next-auth-mock.strategy.ts
2024-08-09 00:39:27 +02:00

25 lines
838 B
TypeScript

import { NextAuthPassportStrategy } from "@/lib/passport/strategies/types";
import { UsersRepository } from "@/modules/users/users.repository";
import { Injectable } from "@nestjs/common";
import { PassportStrategy } from "@nestjs/passport";
@Injectable()
export class NextAuthMockStrategy extends PassportStrategy(NextAuthPassportStrategy, "next-auth") {
constructor(private readonly email: string, private readonly userRepository: UsersRepository) {
super();
}
async authenticate() {
try {
const user = await this.userRepository.findByEmailWithProfile(this.email);
if (!user) {
throw new Error("User with the provided email not found");
}
return this.success(user);
} catch (error) {
console.error(error);
if (error instanceof Error) return this.error(error);
}
}
}