Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🔥 Remove unused auth routes (#2024)

Luke Velladc632bcde9ee
diff --git a/apps/web/src/trpc/routers/auth.ts b/apps/web/src/trpc/routers/auth.ts
index 305ebcc5b..f29737957 100644
--- a/apps/web/src/trpc/routers/auth.ts
+++ b/apps/web/src/trpc/routers/auth.ts
@@ -1,182 +1,9 @@
-import { prisma } from "@rallly/database";
-import { posthog } from "@rallly/posthog/server";
-import { generateOtp } from "@rallly/utils/nanoid";
-import * as Sentry from "@sentry/nextjs";
-import { TRPCError } from "@trpc/server";
import { z } from "zod";
-import { isEmailBlocked } from "@/auth/helpers/is-email-blocked";
-import { mergeGuestsIntoUser } from "@/auth/helpers/merge-user";
-import { isTemporaryEmail } from "@/auth/helpers/temp-email-domains";
-import { trackSpaceCreated } from "@/features/space/analytics";
-import { createSpace } from "@/features/space/mutations";
-
-import { createUser } from "@/features/user/mutations";
-import { getEmailClient } from "@/utils/emails";
-import { getRegistrationEnabled } from "@/utils/get-registration-enabled";
-import { isValidName } from "@/utils/is-valid-name";
-import { createToken, decryptToken } from "@/utils/session";
-import { createRateLimitMiddleware, publicProcedure, router } from "../trpc";
-import type { RegistrationTokenPayload } from "../types";
+import { decryptToken } from "@/utils/session";
+import { publicProcedure, router } from "../trpc";
export const auth = router({
- getUserInfo: publicProcedure
- .input(
- z.object({
- email: z.email(),
- }),
- )
- .mutation(async ({ input }) => {
- const count = await prisma.user.count({
- where: {
- email: input.email,
- },
- });
-
- return { isRegistered: count > 0 };
- }),
- requestRegistration: publicProcedure
- .use(createRateLimitMiddleware("request_registration", 5, "1 m"))
- .input(
- z.object({
- name: z.string().trim().min(1).max(100).refine(isValidName),
- email: z.email(),
- }),
- )
- .mutation(
- async ({
- input,
- ctx,
- }): Promise<
- | { ok: true; token: string }
- | {
- ok: false;
- reason:
- | "userAlreadyExists"
- | "emailNotAllowed"
- | "temporaryEmailNotAllowed";
- }
- > => {
- const isRegistrationEnabled = await getRegistrationEnabled();
- if (!isRegistrationEnabled) {
- throw new TRPCError({
- code: "BAD_REQUEST",
- message: "User registration is disabled",
- });
- }
-
- if (isEmailBlocked?.(input.email)) {
- return { ok: false, reason: "emailNotAllowed" };
- }
-
- if (isTemporaryEmail(input.email)) {
- return { ok: false, reason: "temporaryEmailNotAllowed" };
- }
-
- const user = await prisma.user.findUnique({
- select: {
- id: true,
- },
- where: {
- email: input.email,
- },
- });
-
- if (user) {
- return { ok: false, reason: "userAlreadyExists" };
- }
-
- const code = generateOtp();
-
- const token = await createToken<RegistrationTokenPayload>({
- name: input.name,
- email: input.email,
- code,
- });
-
- await getEmailClient(ctx.locale).sendTemplate("RegisterEmail", {
- to: input.email,
- props: {
- code,
- },
- });
-
- return { ok: true, token };
- },
- ),
- authenticateRegistration: publicProcedure
- .input(
- z.object({
- token: z.string(),
- code: z.string(),
- timeZone: z.string().optional(),
- weekStart: z.number().min(0).max(6).optional(),
- timeFormat: z.enum(["hours12", "hours24"]).optional(),
- locale: z.string().optional(),
- }),
- )
- .mutation(async ({ input, ctx }) => {
- const payload = await decryptToken<RegistrationTokenPayload>(input.token);
-
- if (!payload) {
- return { user: null };
- }
-
- const { name, email, code } = payload;
- if (input.code !== code) {
- return { ok: false };
- }
-
- const user = await createUser({
- name,
- email,
- emailVerified: true,
- timeZone: input.timeZone,
- timeFormat: input.timeFormat,
- weekStart: input.weekStart,
- locale: input.locale,
- });
-
- const space = await createSpace({
- ownerId: user.id,
- });
-
- if (ctx.user?.isGuest) {
- try {
- await mergeGuestsIntoUser(user.id, ctx.user.id);
- } catch (err) {
- Sentry.captureException(err);
- }
- }
-
- posthog?.capture({
- event: "register",
- distinctId: user.id,
- properties: {
- method: "email",
- $set: {
- email: user.email,
- name: user.name,
- timeZone: input.timeZone,
- locale: input.locale,
- tier: "hobby",
- weekStart: input.weekStart,
- timeFormat: input.timeFormat,
- },
- },
- });
-
- trackSpaceCreated({ space, userId: user.id });
-
- return {
- ok: true,
- user: {
- id: user.id,
- name: user.name,
- email: user.email,
- },
- };
- }),
getUserPermission: publicProcedure
.input(z.object({ token: z.string() }))
.query(async ({ input }) => {