GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
// app
import type { AuthServiceDeps } from "./types";

const makeIsExistingEmailAddress: ServiceMethodFactory<
  AuthServiceDeps,
  [string],
  Promise<boolean>
> = ({ request }) => {
  return async (emailAddress) => {
    const matchingUser = await request.prisma.user.findUnique({
      select: {
        id: true,
      },
      where: {
        email: emailAddress,
      },
    });
    return matchingUser != null;
  };
};

export default makeIsExistingEmailAddress;