Jon Higger (He / Him)
Jon Higger (He / Him)
Explore posts from servers
BABetter Auth
Created by DragonCoder99 on 3/25/2025 in #help
Help with Seeding Existing Users into Better Auth
It would be super nice if there were a better auth server instance that you don't have to authenticate with
26 replies
BABetter Auth
Created by DragonCoder99 on 3/25/2025 in #help
Help with Seeding Existing Users into Better Auth
It's not ideal but what I did was this, and I just made sure my local server was running when doing so:
import authClient from "../auth-client";
import { db } from "./db";
import { account, user } from "./schema/auth.schema";

async function seed() {
console.log("🌱 Seeding database...");

// Clean up existing data
await db.delete(account);
await db.delete(user);

await authClient.signUp
.email({
password: "Password123",
name: "jonathan higger",
})
.then(console.log);

await authClient.signUp
.email({
password: "Password123",
name: "jimmy userton",
})
.then(console.log);
// // Create regular user with email/password
}
seed()
.catch((error) => {
console.error("Error seeding database:", error);
process.exit(1);
})
.finally(() => {
process.exit();
});
import authClient from "../auth-client";
import { db } from "./db";
import { account, user } from "./schema/auth.schema";

async function seed() {
console.log("🌱 Seeding database...");

// Clean up existing data
await db.delete(account);
await db.delete(user);

await authClient.signUp
.email({
password: "Password123",
name: "jonathan higger",
})
.then(console.log);

await authClient.signUp
.email({
password: "Password123",
name: "jimmy userton",
})
.then(console.log);
// // Create regular user with email/password
}
seed()
.catch((error) => {
console.error("Error seeding database:", error);
process.exit(1);
})
.finally(() => {
process.exit();
});
26 replies
PPrisma
Created by Jon Higger (He / Him) on 12/8/2024 in #help-and-questions
CreateMany not allowing me to create nested M:N entities
I’ve got a strategy but it’s going to be pretty 🤮
8 replies
PPrisma
Created by Jon Higger (He / Him) on 12/8/2024 in #help-and-questions
CreateMany not allowing me to create nested M:N entities
But items have a many to many with tags 😂
8 replies
PPrisma
Created by Jon Higger (He / Him) on 12/8/2024 in #help-and-questions
CreateMany not allowing me to create nested M:N entities
So restaurants have menus have section groups have sections have items
8 replies
PPrisma
Created by Jon Higger (He / Him) on 12/8/2024 in #help-and-questions
CreateMany not allowing me to create nested M:N entities
Dang that’s going to be a surprisingly painful refactor for me, right now this is a small piece of the puzzle in a large deep clone
8 replies
PPrisma
Created by Jon Higger (He / Him) on 12/8/2024 in #help-and-questions
CreateMany not allowing me to create nested M:N entities
I am currently using prisma with postgres
8 replies
PPrisma
Created by Jon Higger (He / Him) on 11/12/2024 in #help-and-questions
Do transactions work when you nest them?
Only one way, I think you can make something that accepts a full prisma client but not a transaction client, but not vise verce.
12 replies
PPrisma
Created by Jon Higger (He / Him) on 11/12/2024 in #help-and-questions
Do transactions work when you nest them?
export const dbFnA = ({
otherParams,
prismaInstance // can be undefined
}) => {
return transactionOrUseExisting(prismaInstance)($prisma => {

})
}

// That way I either get a transaction when I use dbFnA OR I can also compose it from another fn such that the transaction works across both as if it's one transaction
export const dbFnB = ({
otherParams,
}) => {
return prisma.$transaction(async $prisma => {
const b = await dbFnB({ ...otherParams, prismaInstance: $prisma })
})
}
export const dbFnA = ({
otherParams,
prismaInstance // can be undefined
}) => {
return transactionOrUseExisting(prismaInstance)($prisma => {

})
}

// That way I either get a transaction when I use dbFnA OR I can also compose it from another fn such that the transaction works across both as if it's one transaction
export const dbFnB = ({
otherParams,
}) => {
return prisma.$transaction(async $prisma => {
const b = await dbFnB({ ...otherParams, prismaInstance: $prisma })
})
}
12 replies
PPrisma
Created by Jon Higger (He / Him) on 11/12/2024 in #help-and-questions
Do transactions work when you nest them?
Which can then be used like this
12 replies
PPrisma
Created by Jon Higger (He / Him) on 11/12/2024 in #help-and-questions
Do transactions work when you nest them?
Here's a function I made that basically allows you to either make a transaction inside of a function, or allow you to pass a prisma instance in and use that as the transaction client
/**
* If you pass in a prisma client, it will use that client and not create a new transaction.
* Otherwise it will create a new transaction.
*/
export const transactionOrUseExisting =
(
prismaClient?: Prisma.TransactionClient,
// you can ignore the deferContraints stuff, that's because I need to defer constraints in my transactions specifically for a reordering algorithm
{ deferConstraints = true }: { deferConstraints?: boolean } = {},
) =>
async <T>(
businessLogicCb: (defPrisma: Prisma.TransactionClient) => Promise<T>,
) => {
if (prismaClient) {
if (deferConstraints) {
await runDeferredStatement(prismaClient);
}
return businessLogicCb(prismaClient);
} else {
return prisma.$transaction(async ($prisma) => {
if (deferConstraints) {
await runDeferredStatement($prisma);
}
return businessLogicCb($prisma);
});
}
};
/**
* If you pass in a prisma client, it will use that client and not create a new transaction.
* Otherwise it will create a new transaction.
*/
export const transactionOrUseExisting =
(
prismaClient?: Prisma.TransactionClient,
// you can ignore the deferContraints stuff, that's because I need to defer constraints in my transactions specifically for a reordering algorithm
{ deferConstraints = true }: { deferConstraints?: boolean } = {},
) =>
async <T>(
businessLogicCb: (defPrisma: Prisma.TransactionClient) => Promise<T>,
) => {
if (prismaClient) {
if (deferConstraints) {
await runDeferredStatement(prismaClient);
}
return businessLogicCb(prismaClient);
} else {
return prisma.$transaction(async ($prisma) => {
if (deferConstraints) {
await runDeferredStatement($prisma);
}
return businessLogicCb($prisma);
});
}
};
12 replies
PPrisma
Created by Jon Higger (He / Him) on 11/12/2024 in #help-and-questions
Do transactions work when you nest them?
This is what I did, I just passed the prisma instance around
12 replies