Connect, collaborate, and grow with a community of TypeScript developers
Fix Settings Page Link DB Call (#959)
Maxwell DeMaio492545ca5ed2
diff --git a/apps/web/src/app/[locale]/settings/_components/settings.action.ts b/apps/web/src/app/[locale]/settings/_components/settings.action.tsindex 4936f98b..3ab41479 100644--- a/apps/web/src/app/[locale]/settings/_components/settings.action.ts+++ b/apps/web/src/app/[locale]/settings/_components/settings.action.ts@@ -25,22 +25,44 @@ export async function updateProfile(profileData: ProfileSchema) {data: { bio: profileData.bio },});- // 4. Update the users links in the db if the url is not empty- await prisma.$transaction(- profileData.userLinks.map((link) =>- prisma.userLink.upsert({- where: { id: link.id ?? '' },- update: { url: link.url },- create: {- url: link.url,- user: { connect: { id: session.user.id } },+ // Create an array of user links to create+ const userLinksToCreate = profileData.userLinks.map((link) => ({+ url: link.url,+ user: {+ connect: { id: session.user.id },+ },+ }));++ try {+ await prisma.$transaction([+ // 4. Delete all existing user links for the user+ prisma.userLink.deleteMany({+ where: {+ user: {+ some: {+ id: session.user.id,+ },+ },},}),- ),- );- return { success: true };+ // 5. Insert the new user links+ ...userLinksToCreate.map((userLink) =>+ prisma.userLink.create({+ data: userLink,+ }),+ ),+ ]);+ } catch (error) {+ // Handle the error, and possibly log it+ console.error('Transaction error:', error);+ throw error; // Re-throw the error if needed+ } finally {+ await prisma.$disconnect();+ }// do this after we do the shitrevalidatePath('/settings');++ return { success: true };}diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.tsindex 1f0971bc..0d9aa27b 100644--- a/packages/auth/src/server.ts+++ b/packages/auth/src/server.ts@@ -35,7 +35,7 @@ if (!process.env.GITHUB_SECRET) {}const useSecureCookies = process.env.VERCEL_ENV === 'production';-const cookiePrefix = useSecureCookies ? "__Secure-" : "";+const cookiePrefix = useSecureCookies ? '__Secure-' : '';const cookieDomain = useSecureCookies ? 'typehero.dev' : undefined;export const authOptions: NextAuthOptions = {