refactor: update

This commit is contained in:
Mauricio Siu 2025-02-13 02:36:08 -06:00
parent 7c0d223e17
commit bc901bcb25
5 changed files with 17 additions and 13 deletions

View File

@ -72,7 +72,7 @@ inserted_accounts AS (
SELECT
gen_random_uuid(),
gen_random_uuid(),
'credentials',
'credential',
a."adminId",
auth.password,
COALESCE(auth."is2FAEnabled", false),
@ -166,7 +166,7 @@ inserted_member_accounts AS (
SELECT
gen_random_uuid(),
gen_random_uuid(),
'credentials',
'credential',
u."userId",
auth.password,
COALESCE(auth."is2FAEnabled", false),

View File

@ -54,7 +54,7 @@ await db
.then((user) => user[0]);
await db.insert(schema.account).values({
providerId: "credentials",
providerId: "credential",
userId: user?.id || "",
password: admin.auth.password,
is2FAEnabled: admin.auth.is2FAEnabled || false,
@ -101,7 +101,7 @@ await db
.then((userTemp) => userTemp[0]);
await db.insert(schema.account).values({
providerId: "credentials",
providerId: "credential",
userId: member?.userId || "",
password: member.auth.password,
is2FAEnabled: member.auth.is2FAEnabled || false,

View File

@ -69,8 +69,8 @@ export default function Home({ IS_CLOUD }: Props) {
const router = useRouter();
const form = useForm<Login>({
defaultValues: {
email: "user5@yopmail.com",
password: "Password1234",
email: "",
password: "",
},
resolver: zodResolver(loginSchema),
});

View File

@ -16,7 +16,7 @@ export const lucia = new Lucia(adapter, {
secure: false,
},
},
sessionExpiresIn: new TimeSpan(1, "d"),
getUserAttributes: (attributes) => {
return {

View File

@ -1,23 +1,28 @@
import type { IncomingMessage } from "node:http";
import * as bcrypt from "bcrypt";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { admin, createAuthMiddleware, organization } from "better-auth/plugins";
import { createAuthMiddleware, organization } from "better-auth/plugins";
import { eq } from "drizzle-orm";
import { db } from "../db";
import * as schema from "../db/schema";
import { Scrypt } from "lucia";
const scrypt = new Scrypt();
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
schema: schema,
}),
emailAndPassword: {
enabled: true,
password: {
hash: scrypt.hash,
verify: scrypt.verify,
async hash(password) {
return bcrypt.hashSync(password, 10);
},
async verify({ hash, password }) {
return bcrypt.compareSync(password, hash);
},
},
},
hooks: {
@ -35,7 +40,6 @@ export const auth = betterAuth({
},
user: {
modelName: "users_temp",
additionalFields: {},
},
plugins: [organization()],
});