diff --git a/src/actions/userActions.ts b/src/actions/userActions.ts new file mode 100644 index 0000000..90a10a2 --- /dev/null +++ b/src/actions/userActions.ts @@ -0,0 +1,35 @@ +"use server"; +import { eq, not , asc} from "drizzle-orm"; +import { revalidatePath } from "next/cache"; +import { db } from "@db/index"; +import { usersMerged } from "@schemas/schema"; + +export const getData = async () => { + const data = await db.select().from(usersMerged).orderBy(asc(usersMerged.email)); + return data; +}; + +export const addUser = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => { + await db.insert(usersMerged).values({ + first_name : first_name, last_name: last_name, username: username, email: email, password_hash : password_hash + }); +}; + +export const deleteUser = async (id: string) => { + await db.delete(usersMerged).where(eq(usersMerged.id, id)); + revalidatePath("/"); +}; + +export const editUser = async (id: string, first_name: string, last_name: string, username: string, email : string, password_hash: string) => { + await db + .update(usersMerged) + .set({ + first_name : first_name, + last_name: last_name, + username: username, + email: email, + password_hash: password_hash + }) + .where(eq(usersMerged.id, id)); + revalidatePath("/"); +}; \ No newline at end of file diff --git a/src/app/(siteInfo)/About/page.tsx b/src/app/(siteInfo)/About/page.tsx index 3d20669..e656687 100644 --- a/src/app/(siteInfo)/About/page.tsx +++ b/src/app/(siteInfo)/About/page.tsx @@ -3,7 +3,6 @@ import constants from "@src/lib/constants"; export default function About() { return ( - (
diff --git a/src/app/api/auth/signup/route.tsx b/src/app/api/auth/signup/route.tsx index ca10d18..7cca3d8 100644 --- a/src/app/api/auth/signup/route.tsx +++ b/src/app/api/auth/signup/route.tsx @@ -1,6 +1,6 @@ import { NextResponse } from 'next/server'; -import { db } from '../../../../db'; -import { users } from '../../../../drizzle/schema'; +import { db } from '@db/index'; +import { usersMerged } from '@schemas/schema'; import bcrypt from 'bcryptjs'; import { eq } from 'drizzle-orm'; @@ -14,9 +14,9 @@ export async function POST(request: Request) { username, email, passwordHash: hashedPassword, - } satisfies typeof users.$inferInsert; + } satisfies typeof usersMerged.$inferInsert; - await db.insert(users).values(newUser); + await db.insert(usersMerged).values(newUser); return NextResponse.json( { message: 'User created successfully', redirect: '/' }, diff --git a/src/components/RegistrationForm/index.tsx b/src/components/RegistrationForm/index.tsx index b8f12ae..8a372f1 100644 --- a/src/components/RegistrationForm/index.tsx +++ b/src/components/RegistrationForm/index.tsx @@ -25,7 +25,7 @@ export default function RegistrationForm() { try { // Add your registration API call here console.log('Form submitted:', formData) - router.push('/login') // Redirect to login after successful registration + router.push('/signin') // Redirect to login after successful registration } catch (err) { setError('Failed to register user') } diff --git a/src/drizzle/schema/schema.ts b/src/drizzle/schema/schema.ts index a2422d2..6116fc6 100644 --- a/src/drizzle/schema/schema.ts +++ b/src/drizzle/schema/schema.ts @@ -31,7 +31,6 @@ export const userskeep = pgTable("users-keep", { id: bigserial({ mode: "bigint" }).primaryKey().notNull(), username: varchar({ length: 50 }).notNull(), email: varchar({ length: 255 }).notNull(), - passwordHash: varchar("password_hash", { length: 255 }).notNull(), firstName: varchar("first_name", { length: 50 }), lastName: varchar("last_name", { length: 50 }), @@ -59,9 +58,9 @@ export const usersMerged = pgTable("users-merged", { username: varchar({ length: 50 }).notNull(), email: varchar({ length: 255 }).notNull(), emailVerifiedOn: timestamp("emailVerified", { mode: "date" }), - passwordHash: varchar("password_hash", { length: 255 }).notNull(), - firstName: varchar("first_name", { length: 50 }), - lastName: varchar("last_name", { length: 50 }), + password_hash: varchar("password_hash", { length: 255 }).notNull(), + first_name: varchar("first_name", { length: 50 }), + last_name: varchar("last_name", { length: 50 }), profilePicture: varchar("profile_picture", { length: 255 }), dateOfBirth: date("date_of_birth"), phoneNumber: varchar("phone_number", { length: 20 }),