mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: migrate authentication routes to user router and update related components
This commit continues the refactoring of authentication-related code by: - Moving authentication routes from `auth.ts` to `user.ts` - Updating import paths and function calls across components - Removing commented-out authentication code - Simplifying user-related queries and mutations - Updating server-side authentication handling
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { db } from "@dokploy/server/db";
|
||||
import {
|
||||
type apiCreateUserInvitation,
|
||||
invitation,
|
||||
member,
|
||||
organization,
|
||||
@@ -10,42 +9,6 @@ import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { IS_CLOUD } from "../constants";
|
||||
|
||||
export type User = typeof users_temp.$inferSelect;
|
||||
export const createInvitation = async (
|
||||
_input: typeof apiCreateUserInvitation._type,
|
||||
_adminId: string,
|
||||
) => {
|
||||
// await db.transaction(async (tx) => {
|
||||
// const result = await tx
|
||||
// .insert(auth)
|
||||
// .values({
|
||||
// email: input.email.toLowerCase(),
|
||||
// rol: "user",
|
||||
// password: bcrypt.hashSync("01231203012312", 10),
|
||||
// })
|
||||
// .returning()
|
||||
// .then((res) => res[0]);
|
||||
// if (!result) {
|
||||
// throw new TRPCError({
|
||||
// code: "BAD_REQUEST",
|
||||
// message: "Error creating the user",
|
||||
// });
|
||||
// }
|
||||
// const expiresIn24Hours = new Date();
|
||||
// expiresIn24Hours.setDate(expiresIn24Hours.getDate() + 1);
|
||||
// const token = randomBytes(32).toString("hex");
|
||||
// await tx
|
||||
// .insert(users)
|
||||
// .values({
|
||||
// adminId: adminId,
|
||||
// authId: result.id,
|
||||
// token,
|
||||
// expirationDate: expiresIn24Hours.toISOString(),
|
||||
// })
|
||||
// .returning();
|
||||
// });
|
||||
};
|
||||
|
||||
export const findUserById = async (userId: string) => {
|
||||
const user = await db.query.users_temp.findFirst({
|
||||
where: eq(users_temp.id, userId),
|
||||
@@ -69,34 +32,6 @@ export const findOrganizationById = async (organizationId: string) => {
|
||||
return organizationResult;
|
||||
};
|
||||
|
||||
export const updateUser = async (userId: string, userData: Partial<User>) => {
|
||||
const user = await db
|
||||
.update(users_temp)
|
||||
.set({
|
||||
...userData,
|
||||
})
|
||||
.where(eq(users_temp.id, userId))
|
||||
.returning()
|
||||
.then((res) => res[0]);
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export const updateAdminById = async (
|
||||
_adminId: string,
|
||||
_adminData: Partial<User>,
|
||||
) => {
|
||||
// const admin = await db
|
||||
// .update(admins)
|
||||
// .set({
|
||||
// ...adminData,
|
||||
// })
|
||||
// .where(eq(admins.adminId, adminId))
|
||||
// .returning()
|
||||
// .then((res) => res[0]);
|
||||
// return admin;
|
||||
};
|
||||
|
||||
export const isAdminPresent = async () => {
|
||||
const admin = await db.query.member.findFirst({
|
||||
where: eq(member.role, "owner"),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { db } from "@dokploy/server/db";
|
||||
import { member, type users_temp } from "@dokploy/server/db/schema";
|
||||
import { member, users_temp } from "@dokploy/server/db/schema";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
|
||||
@@ -235,3 +235,16 @@ export const findMemberById = async (
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export const updateUser = async (userId: string, userData: Partial<User>) => {
|
||||
const user = await db
|
||||
.update(users_temp)
|
||||
.set({
|
||||
...userData,
|
||||
})
|
||||
.where(eq(users_temp.id, userId))
|
||||
.returning()
|
||||
.then((res) => res[0]);
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user