mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
working authentication
This commit is contained in:
32
src/app/api/auth/signup/route.tsx
Normal file
32
src/app/api/auth/signup/route.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db } from '../../../../db';
|
||||
import { users } from '../../../../drizzle/schema';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { firstName, username, password, email } = await request.json();
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
|
||||
const newUser = {
|
||||
firstName,
|
||||
username,
|
||||
email,
|
||||
passwordHash: hashedPassword,
|
||||
} satisfies typeof users.$inferInsert;
|
||||
|
||||
await db.insert(users).values(newUser);
|
||||
|
||||
return NextResponse.json(
|
||||
{ message: 'User created successfully', redirect: '/' },
|
||||
{ status: 201 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Signup error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to create user' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user