🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
refactor(api): remove unused user account management endpoints
Bill Yangced536a6f295
diff --git a/server/src/api/user/addUserToOrganization.ts b/server/src/api/user/addUserToOrganization.tsdeleted file mode 100644index 7d8cbec0f..000000000--- a/server/src/api/user/addUserToOrganization.ts+++ /dev/null@@ -1,82 +0,0 @@-import { eq } from "drizzle-orm";-import { FastifyReply, FastifyRequest } from "fastify";-import { db } from "../../db/postgres/postgres.js";-import { member, user } from "../../db/postgres/schema.js";--import { randomBytes } from "crypto";--function generateId(len = 32) {- const alphabet =- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";- const bytes = randomBytes(len);- let id = "";- for (let i = 0; i < len; i++) {- id += alphabet[bytes[i] % alphabet.length];- }- return id;-}--interface AddUserToOrganization {- Body: {- email: string;- role: string;- organizationId: string;- };-}--export async function addUserToOrganization(- request: FastifyRequest<AddUserToOrganization>,- reply: FastifyReply-) {- try {- const { email, role, organizationId } = request.body;-- // Validate input- if (!email || !role || !organizationId) {- return reply.status(400).send({- error: "Missing required fields: email, role, and organizationId",- });- }-- if (role !== "admin" && role !== "member" && role !== "owner") {- return reply.status(400).send({- error: "Role must be either admin, member, or owner",- });- }-- const foundUser = await db.query.user.findFirst({- where: eq(user.email, email),- });-- if (!foundUser) {- return reply.status(404).send({ error: "User not found" });- }-- const foundMember = await db.query.member.findMany({- where: eq(member.userId, foundUser.id),- });-- if (foundMember.length > 0) {- return reply- .status(400)- .send({ error: "user is already in an organization" });- }-- await db.insert(member).values([- {- userId: foundUser.id,- organizationId: organizationId,- role: role,- id: generateId(),- createdAt: new Date().toISOString(),- },- ]);-- return reply.status(201).send({- message: "User added to organization successfully",- });- } catch (error: any) {- console.error(String(error));- return reply.status(500).send({ error: String(error) });- }-}diff --git a/server/src/api/user/createAccount.ts b/server/src/api/user/createAccount.tsdeleted file mode 100644index 58cc04a77..000000000--- a/server/src/api/user/createAccount.ts+++ /dev/null@@ -1,79 +0,0 @@-import { FastifyReply, FastifyRequest } from "fastify";-import { auth } from "../../lib/auth.js";--interface CreateAccountRequest {- Body: {- email: string;- name: string;- password: string;- isAdmin: boolean;- organizationId: string;- };-}--export async function createAccount(- request: FastifyRequest<CreateAccountRequest>,- reply: FastifyReply-) {- try {- const { email, name, password, isAdmin, organizationId } = request.body;-- // Validate input- if (!email || !password || !organizationId || !name) {- return reply.status(400).send({- error:- "Missing required fields: email, name, and password are required",- });- }-- // Check password strength- if (password.length < 8) {- return reply.status(400).send({- error: "Password must be at least 8 characters long",- });- }-- // Create the account using auth.api.signUpEmail- const result = await auth!.api.signUpEmail({- body: { email: "[email protected]", name: "billy3", password: "12345noob" },- });- // const result = await auth!.api.signUpEmail({- // body: {- // email,- // name,- // password,- // },- // });-- await (auth!.api as any).addMember({- body: {- userId: result.user.id,- organizationId: organizationId,- role: isAdmin ? "admin" : "member", // this can also be an array for multiple roles (e.g. ["admin", "sale"])- },- });-- return reply.status(201).send({- message: "Account created successfully",- user: {- id: result.user.id,- email: result.user.email,- name: result.user.name,- },- });- } catch (error: any) {- console.error("Error creating account:", error);-- // Handle specific errors- if (error.message?.includes("unique constraint")) {- if (error.message.includes("username")) {- return reply.status(409).send({ error: "Username already exists" });- }- if (error.message.includes("email")) {- return reply.status(409).send({ error: "Email already exists" });- }- }-- return reply.status(500).send({ error: String(error) });- }-}diff --git a/server/src/index.ts b/server/src/index.tsindex 2358c8adf..3ef51bd24 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -49,8 +49,6 @@ import { createCheckoutSession } from "./api/stripe/createCheckoutSession.js";import { createPortalSession } from "./api/stripe/createPortalSession.js";import { getSubscription } from "./api/stripe/getSubscription.js";import { handleWebhook } from "./api/stripe/webhook.js";-import { addUserToOrganization } from "./api/user/addUserToOrganization.js";-import { createAccount } from "./api/user/createAccount.js";import { getUserOrganizations } from "./api/user/getUserOrganizations.js";import { listOrganizationMembers } from "./api/user/listOrganizationMembers.js";import { initializeCronJobs } from "./cron/index.js";@@ -200,7 +198,9 @@ server.addHook("onRequest", async (request, reply) => {});// Analytics-server.get("/live-user-count/:site", getLiveUsercount);++// This endpoint gets called a lot so we don't want to log it+server.get("/live-user-count/:site", { logLevel: "silent" }, getLiveUsercount);server.get("/overview/:site", getOverview);server.get("/overview-bucketed/:site", getOverviewBucketed);server.get("/single-col/:site", getSingleCol);@@ -242,13 +242,11 @@ server.post("/delete-site/:id", deleteSite);server.get("/get-sites", getSites);server.get("/get-sites-from-org/:organizationId", getSitesFromOrg);server.get("/get-site/:id", getSite);-server.post("/create-account", createAccount);server.get("/list-organization-members/:organizationId",listOrganizationMembers);server.get("/user/organizations", getUserOrganizations);-server.post("/add-user-to-organization", addUserToOrganization);if (IS_CLOUD) {// Stripe Routes