mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix
This commit is contained in:
+38
-34
@@ -1,45 +1,49 @@
|
||||
import {SignUpUser} from "@/types/auth";
|
||||
import {hashPassword} from "better-auth/crypto";
|
||||
import {db} from "@/db";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {User, UserThemeEnum} from "@/db/schema/02_user";
|
||||
import {assertValidPassword} from "@/utils/password";
|
||||
"use server";
|
||||
|
||||
import { SignUpUser } from "@/types/auth";
|
||||
import { hashPassword } from "better-auth/crypto";
|
||||
import { db } from "@/db";
|
||||
import * as drizzleDb from "@/db";
|
||||
import { User, UserThemeEnum } from "@/db/schema/02_user";
|
||||
import { assertValidPassword } from "@/utils/password";
|
||||
|
||||
export async function hasUsers(): Promise<boolean> {
|
||||
const result = await db.select().from(drizzleDb.schemas.user).limit(1);
|
||||
return result.length > 0;
|
||||
const result = await db.select().from(drizzleDb.schemas.user).limit(1);
|
||||
return result.length > 0;
|
||||
}
|
||||
|
||||
export async function createUserDb(data: SignUpUser): Promise<User> {
|
||||
assertValidPassword(data.password);
|
||||
assertValidPassword(data.password);
|
||||
|
||||
const now = new Date();
|
||||
const userId = crypto.randomUUID();
|
||||
const now = new Date();
|
||||
const userId = crypto.randomUUID();
|
||||
|
||||
const [newUser] = await db.insert(drizzleDb.schemas.user).values({
|
||||
...data,
|
||||
id: userId,
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
emailVerified: true,
|
||||
role: data.role,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
theme: data.theme as UserThemeEnum,
|
||||
}).returning();
|
||||
const [newUser] = await db
|
||||
.insert(drizzleDb.schemas.user)
|
||||
.values({
|
||||
...data,
|
||||
id: userId,
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
emailVerified: true,
|
||||
role: data.role,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
theme: data.theme as UserThemeEnum,
|
||||
})
|
||||
.returning();
|
||||
|
||||
if (data.password) {
|
||||
const hashedPassword = await hashPassword(data.password);
|
||||
await db.insert(drizzleDb.schemas.account).values({
|
||||
providerId: "credential",
|
||||
accountId: userId,
|
||||
userId: userId,
|
||||
password: hashedPassword,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
}
|
||||
if (data.password) {
|
||||
const hashedPassword = await hashPassword(data.password);
|
||||
await db.insert(drizzleDb.schemas.account).values({
|
||||
providerId: "credential",
|
||||
accountId: userId,
|
||||
userId: userId,
|
||||
password: hashedPassword,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
}
|
||||
|
||||
return newUser
|
||||
return newUser;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user