mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
userRegistration work
This commit is contained in:
@@ -6,14 +6,14 @@ import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { firstName, username, password, email } = await request.json();
|
||||
const { first_name, username, password, email } = await request.json();
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
|
||||
const newUser = {
|
||||
firstName,
|
||||
first_name,
|
||||
username,
|
||||
email,
|
||||
passwordHash: hashedPassword,
|
||||
password_hash: hashedPassword,
|
||||
} satisfies typeof usersMerged.$inferInsert;
|
||||
|
||||
await db.insert(usersMerged).values(newUser);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
|
||||
import { addUser } from "@actions/userActions"
|
||||
export default function RegistrationForm() {
|
||||
const router = useRouter()
|
||||
const [error, setError] = useState('')
|
||||
@@ -16,14 +16,17 @@ export default function RegistrationForm() {
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
|
||||
alert('in the submit');
|
||||
alert(formData.password + ":" + formData.confirmPassword);
|
||||
if (formData.password !== formData.confirmPassword) {
|
||||
setError('Passwords do not match')
|
||||
console.log("password no match");
|
||||
alert('password no match');
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// Add your registration API call here
|
||||
addUser(formData.name, formData.name, formData.name, formData.email, formData.password);
|
||||
console.log('Form submitted:', formData)
|
||||
router.push('/signin') // Redirect to login after successful registration
|
||||
} catch (err) {
|
||||
|
||||
@@ -16,51 +16,18 @@ export const products = pgTable("products", {
|
||||
deletedAt: timestamp("deleted_at", { mode: 'string' }),
|
||||
});
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
name: text("name"),
|
||||
email: text("email").unique(),
|
||||
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||
image: text("image"),
|
||||
})
|
||||
|
||||
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 }),
|
||||
profilePicture: varchar("profile_picture", { length: 255 }),
|
||||
dateOfBirth: date("date_of_birth"),
|
||||
phoneNumber: varchar("phone_number", { length: 20 }),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
isAdmin: boolean("is_admin").default(false),
|
||||
lastLogin: timestamp("last_login", { mode: 'string' }),
|
||||
emailVerified: boolean("email_verified").default(false),
|
||||
buildPrivacySetting: text("build_privacy_setting").default('public'),
|
||||
uuid: uuid().defaultRandom(),
|
||||
}, (table) => {
|
||||
return {
|
||||
usersUsernameKey: unique("users_username_key").on(table.username),
|
||||
usersEmailKey: unique("users_email_key").on(table.email),
|
||||
usersBuildPrivacySettingCheck: check("users_build_privacy_setting_check", sql`build_privacy_setting = ANY (ARRAY['private'::text, 'public'::text])`),
|
||||
}
|
||||
});
|
||||
export const usersMerged = pgTable("users-merged", {
|
||||
export const usersMerged = pgTable("users", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
username: varchar({ length: 50 }).notNull(),
|
||||
email: varchar({ length: 255 }).notNull(),
|
||||
emailVerifiedOn: timestamp("emailVerified", { mode: "date" }),
|
||||
emailVerifiedOn: timestamp("emailVerifiedOn", { mode: "date" }),
|
||||
password_hash: varchar("password_hash", { length: 255 }).notNull(),
|
||||
first_name: varchar("first_name", { length: 50 }),
|
||||
last_name: varchar("last_name", { length: 50 }),
|
||||
full_name: varchar("full_name", { length: 50 }),
|
||||
profilePicture: varchar("profile_picture", { length: 255 }),
|
||||
dateOfBirth: date("date_of_birth"),
|
||||
phoneNumber: varchar("phone_number", { length: 20 }),
|
||||
|
||||
Reference in New Issue
Block a user