mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
chore: clean up unused variables and improve error handling across codebase
This commit focuses on removing unused variables, adding placeholder error handling, and generally tidying up various files across the Dokploy application. Changes include: - Removing unused imports and variables - Adding placeholder error handling in catch blocks - Cleaning up commented-out code - Removing deprecated utility files - Improving type safety and code consistency
This commit is contained in:
@@ -2,14 +2,12 @@ import type { IncomingMessage } from "node:http";
|
||||
import * as bcrypt from "bcrypt";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import {
|
||||
createAuthMiddleware,
|
||||
organization,
|
||||
twoFactor,
|
||||
} from "better-auth/plugins";
|
||||
import { organization, twoFactor } from "better-auth/plugins";
|
||||
import { and, desc, eq } from "drizzle-orm";
|
||||
import { db } from "../db";
|
||||
import * as schema from "../db/schema";
|
||||
import { sendVerificationEmail } from "../verification/send-verification-email";
|
||||
import { IS_CLOUD } from "../constants";
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: drizzleAdapter(db, {
|
||||
@@ -27,9 +25,18 @@ export const auth = betterAuth({
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
|
||||
},
|
||||
},
|
||||
emailVerification: {
|
||||
sendOnSignUp: true,
|
||||
autoSignInAfterVerification: true,
|
||||
sendVerificationEmail: async ({ user, url }) => {
|
||||
console.log("Sending verification email to", user.email);
|
||||
await sendVerificationEmail(user.email, url);
|
||||
},
|
||||
},
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
|
||||
autoSignIn: !IS_CLOUD,
|
||||
requireEmailVerification: IS_CLOUD,
|
||||
password: {
|
||||
async hash(password) {
|
||||
return bcrypt.hashSync(password, 10);
|
||||
@@ -39,33 +46,37 @@ export const auth = betterAuth({
|
||||
},
|
||||
},
|
||||
},
|
||||
hooks: {
|
||||
after: createAuthMiddleware(async (ctx) => {
|
||||
if (ctx.path.startsWith("/sign-up")) {
|
||||
const newSession = ctx.context.newSession;
|
||||
if (ctx.headers?.get("x-dokploy-token")) {
|
||||
} else {
|
||||
const organization = await db
|
||||
.insert(schema.organization)
|
||||
.values({
|
||||
name: "My Organization",
|
||||
ownerId: newSession?.user?.id || "",
|
||||
createdAt: new Date(),
|
||||
})
|
||||
.returning()
|
||||
.then((res) => res[0]);
|
||||
|
||||
await db.insert(schema.member).values({
|
||||
userId: newSession?.user?.id || "",
|
||||
organizationId: organization?.id || "",
|
||||
role: "owner",
|
||||
createdAt: new Date(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
},
|
||||
databaseHooks: {
|
||||
user: {
|
||||
create: {
|
||||
after: async (user) => {
|
||||
const isAdminPresent = await db.query.member.findFirst({
|
||||
where: eq(schema.member.role, "owner"),
|
||||
});
|
||||
|
||||
if (IS_CLOUD || !isAdminPresent) {
|
||||
await db.transaction(async (tx) => {
|
||||
const organization = await tx
|
||||
.insert(schema.organization)
|
||||
.values({
|
||||
name: "My Organization",
|
||||
ownerId: user.id,
|
||||
createdAt: new Date(),
|
||||
})
|
||||
.returning()
|
||||
.then((res) => res[0]);
|
||||
|
||||
await tx.insert(schema.member).values({
|
||||
userId: user.id,
|
||||
organizationId: organization?.id || "",
|
||||
role: "owner",
|
||||
createdAt: new Date(),
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
session: {
|
||||
create: {
|
||||
before: async (session) => {
|
||||
@@ -106,7 +117,7 @@ export const auth = betterAuth({
|
||||
plugins: [
|
||||
twoFactor(),
|
||||
organization({
|
||||
async sendInvitationEmail(data, request) {
|
||||
async sendInvitationEmail(data, _request) {
|
||||
const inviteLink = `https://example.com/accept-invitation/${data.id}`;
|
||||
// https://example.com/accept-invitation/8jlBi9Tb9isDb8mc8Sb85u1BaJYklKB2
|
||||
// sendOrganizationInvitation({
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
// import {
|
||||
// decodeHex,
|
||||
// encodeBase32LowerCaseNoPadding,
|
||||
// encodeHexLowerCase,
|
||||
// } from "@oslojs/encoding";
|
||||
// import { generateRandomString } from "@oslojs/crypto/random";
|
||||
// import { constantTimeEqual } from "@oslojs/crypto/subtle";
|
||||
// import { scrypt } from "./scrypt/index";
|
||||
|
||||
// import type { RandomReader } from "@oslojs/crypto/random";
|
||||
|
||||
// async function generateScryptKey(
|
||||
// data: string,
|
||||
// salt: string,
|
||||
// blockSize = 16,
|
||||
// ): Promise<Uint8Array> {
|
||||
// const encodedData = new TextEncoder().encode(data);
|
||||
// const encodedSalt = new TextEncoder().encode(salt);
|
||||
// const keyUint8Array = await scrypt(encodedData, encodedSalt, {
|
||||
// N: 16384,
|
||||
// r: blockSize,
|
||||
// p: 1,
|
||||
// dkLen: 64,
|
||||
// });
|
||||
// return new Uint8Array(keyUint8Array);
|
||||
// }
|
||||
|
||||
// const random: RandomReader = {
|
||||
// read(bytes: Uint8Array): void {
|
||||
// crypto.getRandomValues(bytes);
|
||||
// },
|
||||
// };
|
||||
|
||||
// export function generateId(length: number): string {
|
||||
// const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
// return generateRandomString(random, alphabet, length);
|
||||
// }
|
||||
|
||||
// export function generateIdFromEntropySize(size: number): string {
|
||||
// const buffer = crypto.getRandomValues(new Uint8Array(size));
|
||||
// return encodeBase32LowerCaseNoPadding(buffer);
|
||||
// }
|
||||
|
||||
// export class Scrypt implements PasswordHashingAlgorithm {
|
||||
// async hash(password: string): Promise<string> {
|
||||
// const salt = encodeHexLowerCase(crypto.getRandomValues(new Uint8Array(16)));
|
||||
// const key = await generateScryptKey(password.normalize("NFKC"), salt);
|
||||
// return `${salt}:${encodeHexLowerCase(key)}`;
|
||||
// }
|
||||
// async verify(hash: string, password: string): Promise<boolean> {
|
||||
// const parts = hash.split(":");
|
||||
// if (parts.length !== 2) return false;
|
||||
|
||||
// const [salt, key] = parts;
|
||||
// const targetKey = await generateScryptKey(password.normalize("NFKC"), salt);
|
||||
// return constantTimeEqual(targetKey, decodeHex(key));
|
||||
// }
|
||||
// }
|
||||
|
||||
// export class LegacyScrypt implements PasswordHashingAlgorithm {
|
||||
// async hash(password: string): Promise<string> {
|
||||
// const salt = encodeHexLowerCase(crypto.getRandomValues(new Uint8Array(16)));
|
||||
// const key = await generateScryptKey(password.normalize("NFKC"), salt);
|
||||
// return `s2:${salt}:${encodeHexLowerCase(key)}`;
|
||||
// }
|
||||
// async verify(hash: string, password: string): Promise<boolean> {
|
||||
// const parts = hash.split(":");
|
||||
// if (parts.length === 2) {
|
||||
// const [salt, key] = parts;
|
||||
// const targetKey = await generateScryptKey(
|
||||
// password.normalize("NFKC"),
|
||||
// salt,
|
||||
// 8,
|
||||
// );
|
||||
// const result = constantTimeEqual(targetKey, decodeHex(key));
|
||||
// return result;
|
||||
// }
|
||||
// if (parts.length !== 3) return false;
|
||||
// const [version, salt, key] = parts;
|
||||
// if (version === "s2") {
|
||||
// const targetKey = await generateScryptKey(
|
||||
// password.normalize("NFKC"),
|
||||
// salt,
|
||||
// );
|
||||
// return constantTimeEqual(targetKey, decodeHex(key));
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// export interface PasswordHashingAlgorithm {
|
||||
// hash(password: string): Promise<string>;
|
||||
// verify(hash: string, password: string): Promise<boolean>;
|
||||
// }
|
||||
@@ -1 +0,0 @@
|
||||
//
|
||||
Reference in New Issue
Block a user