mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
fix: check db initialisation on getOrCreateCloudUser
This commit is contained in:
@@ -41,10 +41,6 @@ export default async function CloudPaymentSuccessPage({
|
|||||||
aiBalance: plan?.limits.ai,
|
aiBalance: plan?.limits.ai,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (await isDatabaseEmpty(user.id)) {
|
|
||||||
await createUserDefaults(user.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="w-full max-w-xl mx-auto p-8 flex flex-col items-center justify-center gap-4">
|
<Card className="w-full max-w-xl mx-auto p-8 flex flex-col items-center justify-center gap-4">
|
||||||
<Cake className="w-36 h-36" />
|
<Cake className="w-36 h-36" />
|
||||||
|
|||||||
@@ -92,10 +92,6 @@ async function handleUserSubscriptionUpdate(
|
|||||||
name: customer.name as string,
|
name: customer.name as string,
|
||||||
stripeCustomerId: customer.id,
|
stripeCustomerId: customer.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (await isDatabaseEmpty(user.id)) {
|
|
||||||
await createUserDefaults(user.id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMembershipExpiresAt = new Date(item.current_period_end * 1000)
|
const newMembershipExpiresAt = new Date(item.current_period_end * 1000)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { prisma } from "@/lib/db"
|
import { prisma } from "@/lib/db"
|
||||||
import { Prisma } from "@/prisma/client"
|
import { Prisma } from "@/prisma/client"
|
||||||
import { cache } from "react"
|
import { cache } from "react"
|
||||||
|
import { isDatabaseEmpty } from "./defaults"
|
||||||
|
import { createUserDefaults } from "./defaults"
|
||||||
|
|
||||||
export const SELF_HOSTED_USER = {
|
export const SELF_HOSTED_USER = {
|
||||||
email: "taxhacker@localhost",
|
email: "taxhacker@localhost",
|
||||||
@@ -26,12 +28,18 @@ export const getOrCreateSelfHostedUser = cache(async () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export function getOrCreateCloudUser(email: string, data: Prisma.UserCreateInput) {
|
export async function getOrCreateCloudUser(email: string, data: Prisma.UserCreateInput) {
|
||||||
return prisma.user.upsert({
|
const user = await prisma.user.upsert({
|
||||||
where: { email: email.toLowerCase() },
|
where: { email: email.toLowerCase() },
|
||||||
update: data,
|
update: data,
|
||||||
create: data,
|
create: data,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (await isDatabaseEmpty(user.id)) {
|
||||||
|
await createUserDefaults(user.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getUserById = cache(async (id: string) => {
|
export const getUserById = cache(async (id: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user