mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
fix: always lowercase user email
This commit is contained in:
@@ -71,6 +71,8 @@ async function handleUserSubscriptionUpdate(
|
|||||||
customerId: string,
|
customerId: string,
|
||||||
item: Stripe.SubscriptionItem
|
item: Stripe.SubscriptionItem
|
||||||
) {
|
) {
|
||||||
|
console.log(`Updating subscription for customer ${customerId}`)
|
||||||
|
|
||||||
if (!stripeClient) {
|
if (!stripeClient) {
|
||||||
return new NextResponse("Stripe client is not initialized", { status: 500 })
|
return new NextResponse("Stripe client is not initialized", { status: 500 })
|
||||||
}
|
}
|
||||||
@@ -83,6 +85,8 @@ async function handleUserSubscriptionUpdate(
|
|||||||
let user = await getUserByStripeCustomerId(customerId)
|
let user = await getUserByStripeCustomerId(customerId)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
const customer = (await stripeClient.customers.retrieve(customerId)) as Stripe.Customer
|
const customer = (await stripeClient.customers.retrieve(customerId)) as Stripe.Customer
|
||||||
|
console.log(`User not found for customer ${customerId}, creating new user with email ${customer.email}`)
|
||||||
|
|
||||||
user = await getOrCreateCloudUser(customer.email as string, {
|
user = await getOrCreateCloudUser(customer.email as string, {
|
||||||
email: customer.email as string,
|
email: customer.email as string,
|
||||||
name: customer.name as string,
|
name: customer.name as string,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const getOrCreateSelfHostedUser = cache(async () => {
|
|||||||
|
|
||||||
export function getOrCreateCloudUser(email: string, data: Prisma.UserCreateInput) {
|
export function getOrCreateCloudUser(email: string, data: Prisma.UserCreateInput) {
|
||||||
return prisma.user.upsert({
|
return prisma.user.upsert({
|
||||||
where: { email },
|
where: { email: email.toLowerCase() },
|
||||||
update: data,
|
update: data,
|
||||||
create: data,
|
create: data,
|
||||||
})
|
})
|
||||||
@@ -42,7 +42,7 @@ export const getUserById = cache(async (id: string) => {
|
|||||||
|
|
||||||
export const getUserByEmail = cache(async (email: string) => {
|
export const getUserByEmail = cache(async (email: string) => {
|
||||||
return await prisma.user.findUnique({
|
return await prisma.user.findUnique({
|
||||||
where: { email },
|
where: { email: email.toLowerCase() },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user