Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

remove unused

Bill Yang471e297e2f88
diff --git a/server/src/lib/auth.ts b/server/src/lib/auth.ts
index 626d274c5..fe8bf292c 100644
--- a/server/src/lib/auth.ts
+++ b/server/src/lib/auth.ts
@@ -1,6 +1,5 @@
import { betterAuth } from "better-auth";
-import { drizzleAdapter } from "better-auth/adapters/drizzle";
-import { admin, emailOTP, organization, captcha } from "better-auth/plugins";
+import { admin, captcha, emailOTP, organization } from "better-auth/plugins";
import dotenv from "dotenv";
import { asc, eq } from "drizzle-orm";
import pg from "pg";
@@ -171,95 +170,3 @@ export let auth: AuthType | null = betterAuth({
},
},
});
-
-export function initAuth(allowedOrigins: string[]) {
- auth = betterAuth({
- basePath: "/api/auth",
- database: drizzleAdapter(db, {
- provider: "pg",
- schema: {
- // Map our schema tables to what better-auth expects
- user: schema.user,
- account: schema.account,
- session: schema.session,
- verification: schema.verification,
- organization: schema.organization,
- member: schema.member,
- },
- }),
- experimental: {
- sessionCookie: {
- domains: allowedOrigins,
- },
- },
- emailAndPassword: {
- enabled: true,
- // Disable email verification for now
- requireEmailVerification: false,
- disableSignUp: DISABLE_SIGNUP,
- },
- socialProviders: {
- google: {
- clientId: process.env.GOOGLE_CLIENT_ID!,
- clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
- },
- github: {
- clientId: process.env.GITHUB_CLIENT_ID!,
- clientSecret: process.env.GITHUB_CLIENT_SECRET!,
- },
- // twitter: {
- // clientId: process.env.TWITTER_CLIENT_ID!,
- // clientSecret: process.env.TWITTER_CLIENT_SECRET!,
- // },
- },
- user: {
- additionalFields: {
- sendAutoEmailReports: {
- type: "boolean",
- required: true,
- defaultValue: true,
- input: true,
- },
- },
- changeEmail: {
- enabled: true,
- },
- },
- plugins: pluginList,
- trustedOrigins: allowedOrigins,
- advanced: {
- useSecureCookies: process.env.NODE_ENV === "production",
- defaultCookieAttributes: {
- sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
- path: "/",
- },
- },
- databaseHooks: {
- user: {
- create: {
- after: async () => {
- const users = await db.select().from(schema.user).orderBy(asc(user.createdAt));
-
- // If this is the first user, make them an admin
- if (users.length === 1) {
- await db.update(user).set({ role: "admin" }).where(eq(user.id, users[0].id));
- }
- },
- },
- update: {
- before: async userUpdate => {
- // Security: Prevent role field from being updated via regular update-user endpoint
- // Role changes should only go through the admin setRole endpoint
- if (userUpdate && typeof userUpdate === "object" && "role" in userUpdate) {
- // Remove role from the update data
- const { role: _, ...dataWithoutRole } = userUpdate;
- return {
- data: dataWithoutRole,
- };
- }
- },
- },
- },
- },
- });
-}