1.0.0
This commit is contained in:
@@ -6,11 +6,9 @@ import { eq, count, sql } from 'drizzle-orm';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
export const POST: APIRoute = async ({ request, cookies, redirect }) => {
|
||||
// Check if this is the first user
|
||||
const userCountResult = await db.select({ count: count() }).from(users).get();
|
||||
const isFirstUser = userCountResult ? userCountResult.count === 0 : true;
|
||||
|
||||
// If not first user, check if registration is enabled
|
||||
if (!isFirstUser) {
|
||||
const registrationSetting = await db.select()
|
||||
.from(siteSettings)
|
||||
@@ -33,7 +31,6 @@ export const POST: APIRoute = async ({ request, cookies, redirect }) => {
|
||||
return new Response('Missing fields', { status: 400 });
|
||||
}
|
||||
|
||||
// Check if user exists
|
||||
const existingUser = await db.select().from(users).where(eq(users.email, email)).get();
|
||||
if (existingUser) {
|
||||
return new Response('User already exists', { status: 400 });
|
||||
@@ -42,7 +39,6 @@ export const POST: APIRoute = async ({ request, cookies, redirect }) => {
|
||||
const passwordHash = await hashPassword(password);
|
||||
const userId = nanoid();
|
||||
|
||||
// Create user
|
||||
await db.insert(users).values({
|
||||
id: userId,
|
||||
name,
|
||||
@@ -51,21 +47,18 @@ export const POST: APIRoute = async ({ request, cookies, redirect }) => {
|
||||
isSiteAdmin: isFirstUser,
|
||||
});
|
||||
|
||||
// Create default organization
|
||||
const orgId = nanoid();
|
||||
await db.insert(organizations).values({
|
||||
id: orgId,
|
||||
name: `${name}'s Organization`,
|
||||
});
|
||||
|
||||
// Add user to organization
|
||||
await db.insert(members).values({
|
||||
userId,
|
||||
organizationId: orgId,
|
||||
role: 'owner',
|
||||
});
|
||||
|
||||
// Create session
|
||||
const { sessionId, expiresAt } = await createSession(userId);
|
||||
|
||||
cookies.set('session_id', sessionId, {
|
||||
|
||||
Reference in New Issue
Block a user