Files
calendar/apps/api/v2/test/mocks/api-auth-mock.strategy.ts
T
MorganandGitHub 9a473d5b55 chore: auth on api-v2 with api-key (#15455)
* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* fixup! chore: enable apiv2 auth with api keys

* fixup! Merge branch 'chore-apiv2-auth-api-key' of github.com:calcom/cal.com into chore-apiv2-auth-api-key

* fixup! fixup! Merge branch 'chore-apiv2-auth-api-key' of github.com:calcom/cal.com into chore-apiv2-auth-api-key

* fixup! fixup! fixup! Merge branch 'chore-apiv2-auth-api-key' of github.com:calcom/cal.com into chore-apiv2-auth-api-key
2024-06-19 16:00:22 +00:00

26 lines
801 B
TypeScript

import { BaseStrategy } 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 ApiAuthMockStrategy extends PassportStrategy(BaseStrategy, "api-auth") {
constructor(private readonly email: string, private readonly usersRepository: UsersRepository) {
super();
}
async authenticate() {
try {
const user = await this.usersRepository.findByEmail(this.email);
if (!user) {
throw new Error("User with the provided ID not found");
}
return this.success(user);
} catch (error) {
console.error(error);
if (error instanceof Error) return this.error(error);
}
}
}