From 99d765d401f0ce77efc53d41d270a96d493248f8 Mon Sep 17 00:00:00 2001 From: P J Borowiecki Date: Sun, 5 Nov 2023 10:58:41 +0100 Subject: [PATCH] Fix next-contentlayer warnings and Vercel deployment build error --- .gitignore | 5 ++++- components.json | 2 +- next.config.js => next.config.cjs | 7 ++++++- src/actions/email.ts | 20 +++++++++++++++++++ src/actions/user.ts | 2 +- src/app/(auth)/signup/page.tsx | 1 - src/app/(auth)/signup/verify-email/page.tsx | 19 ++++-------------- .../emails/email-verification-email.tsx | 12 ----------- src/components/emails/magic-link-email.tsx | 11 ---------- .../emails/reset-password-email.tsx | 11 ---------- tsconfig.json | 9 ++++----- 11 files changed, 40 insertions(+), 59 deletions(-) rename next.config.js => next.config.cjs (73%) diff --git a/.gitignore b/.gitignore index 76e7f15..3d936ea 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,7 @@ yarn-error.log* next-env.d.ts # certificates -certificates \ No newline at end of file +certificates + +# content +.contentlayer \ No newline at end of file diff --git a/components.json b/components.json index e6020a8..8d04127 100644 --- a/components.json +++ b/components.json @@ -13,4 +13,4 @@ "components": "@/components", "utils": "@/lib/utils" } -} \ No newline at end of file +} diff --git a/next.config.js b/next.config.cjs similarity index 73% rename from next.config.js rename to next.config.cjs index 8b25e57..54c5f6a 100644 --- a/next.config.js +++ b/next.config.cjs @@ -1,8 +1,13 @@ +import { withContentlayer } from "next-contentlayer" + import("./src/env.mjs") /** @type {import("next").NextConfig} */ const nextConfig = { reactStrictMode: true, + experimental: { + webpackBuildWorker: true, + }, images: { remotePatterns: [ { @@ -21,4 +26,4 @@ const nextConfig = { }, } -module.exports = nextConfig +export default withContentlayer(nextConfig) diff --git a/src/actions/email.ts b/src/actions/email.ts index 1461263..0ade241 100644 --- a/src/actions/email.ts +++ b/src/actions/email.ts @@ -4,6 +4,7 @@ import crypto from "crypto" import { getUserByEmail } from "@/actions/user" import { prisma } from "@/db" import { env } from "@/env.mjs" +import { type User } from "@prisma/client" import { type CreateEmailOptions, type CreateEmailRequestOptions, @@ -72,3 +73,22 @@ export async function checkIfEmailVerified(email: string): Promise { throw new Error("Error checking if email verified") } } + +export async function markEmailAsVerified( + emailVerificationToken: string +): Promise { + try { + return await prisma.user.update({ + where: { + emailVerificationToken, + }, + data: { + emailVerified: new Date(), + emailVerificationToken: null, + }, + }) + } catch (error) { + console.error(error) + throw new Error("Error marking email as verified") + } +} diff --git a/src/actions/user.ts b/src/actions/user.ts index 4f9986a..57918e1 100644 --- a/src/actions/user.ts +++ b/src/actions/user.ts @@ -44,4 +44,4 @@ export async function getUserByEmailVerificationToken( console.error(error) throw new Error("Error getting user by email verification token") } -} +} \ No newline at end of file diff --git a/src/app/(auth)/signup/page.tsx b/src/app/(auth)/signup/page.tsx index 53556ea..4163132 100644 --- a/src/app/(auth)/signup/page.tsx +++ b/src/app/(auth)/signup/page.tsx @@ -4,7 +4,6 @@ import { redirect } from "next/navigation" import { env } from "@/env.mjs" import { getCurrentUser } from "@/lib/auth" -import { cn } from "@/lib/utils" import { buttonVariants } from "@/components/ui/button" import { Card, diff --git a/src/app/(auth)/signup/verify-email/page.tsx b/src/app/(auth)/signup/verify-email/page.tsx index 188548e..8bffd2a 100644 --- a/src/app/(auth)/signup/verify-email/page.tsx +++ b/src/app/(auth)/signup/verify-email/page.tsx @@ -1,8 +1,8 @@ import { type Metadata } from "next" import Link from "next/link" import { redirect } from "next/navigation" +import { markEmailAsVerified } from "@/actions/email" import { getUserByEmailVerificationToken } from "@/actions/user" -import { prisma } from "@/db" import { env } from "@/env.mjs" import { cn } from "@/lib/utils" @@ -22,7 +22,7 @@ export const metadata: Metadata = { description: "Verify your email address to continue", } -interface VerifyEmailPageProps { +export interface VerifyEmailPageProps { searchParams: { [key: string]: string | string[] | undefined } } @@ -63,19 +63,8 @@ export default async function VerifyEmailPage({ ) } - const updatedUser = await prisma.user.update({ - where: { - emailVerificationToken, - }, - data: { - emailVerified: new Date(), - emailVerificationToken: null, - }, - }) - - if (!updatedUser) { - redirect("/signup") - } + const updatedUser = await markEmailAsVerified(emailVerificationToken) + if (!updatedUser) redirect("/signup") return (
diff --git a/src/components/emails/email-verification-email.tsx b/src/components/emails/email-verification-email.tsx index 216ca97..48b5e96 100644 --- a/src/components/emails/email-verification-email.tsx +++ b/src/components/emails/email-verification-email.tsx @@ -10,18 +10,6 @@ import { Section } from "@react-email/section" import { Tailwind } from "@react-email/tailwind" import { Text } from "@react-email/text" -// import { -// Body, -// Button, -// Container, -// Head, -// Html, -// Preview, -// Section, -// Tailwind, -// Text, -// } from "@react-email/components" - import { siteConfig } from "@/config/site" interface EmailVerificationEmailProps { diff --git a/src/components/emails/magic-link-email.tsx b/src/components/emails/magic-link-email.tsx index 2faa95f..6a2c8ac 100644 --- a/src/components/emails/magic-link-email.tsx +++ b/src/components/emails/magic-link-email.tsx @@ -1,14 +1,3 @@ -// import { -// Body, -// Button, -// Container, -// Head, -// Html, -// Preview, -// Section, -// Tailwind, -// Text, -// } from "@react-email/components" import { Body } from "@react-email/body" import { Button } from "@react-email/button" import { Container } from "@react-email/container" diff --git a/src/components/emails/reset-password-email.tsx b/src/components/emails/reset-password-email.tsx index 5d8dd60..e627898 100644 --- a/src/components/emails/reset-password-email.tsx +++ b/src/components/emails/reset-password-email.tsx @@ -1,15 +1,4 @@ import * as React from "react" -// import { -// Body, -// Button, -// Container, -// Head, -// Html, -// Preview, -// Section, -// Tailwind, -// Text, -// } from "@jsx-email/all" import { Body } from "@react-email/body" import { Button } from "@react-email/button" import { Container } from "@react-email/container" diff --git a/tsconfig.json b/tsconfig.json index 7d9df9a..23ddb6a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,15 +28,14 @@ }, "include": [ "next-env.d.ts", - "**/*.js", - "**/*.cjs", - "**/*.mjs", "**/*.ts", - "**/*.jsx", "**/*.tsx", + "**/*.cjs", + "**/*.mjs", ".next/types/**/*.ts", "./contentlayer.config.js", - ".contentlayer/generated" + ".contentlayer/generated", + "next.config.cjs" ], "exclude": ["node_modules"] }