adrianhajdin / ai_saas_app

Build a REAL Software-as-a-Service app with AI features and payments & credits system that you might even turn into a side income or business idea using Next.js 14, Clerk, MongoDB, Cloudinary AI, and Stripe.
https://jsmastery.pro
926 stars 279 forks source link

Unhandled Runtime Error #27

Open sikta-roy opened 5 days ago

sikta-roy commented 5 days ago

I got an error at around 1hour 57min into the video tutorial,

the error was:

Screenshot 2024-07-03 120731

sikta-roy commented 5 days ago

If i update the: app(root)\transformations\add[type]\page.tsx

import Header from "@/components/shared/Header"; import TransformationForm from "@/components/shared/TransformationForm"; import { transformationTypes } from "@/constants"; import { getUserById } from "@/lib/actions/user.actions"; import { auth } from "@clerk/nextjs/server"; import { redirect } from "next/navigation";

const AddTransformationTypePage = async ({ params: { type } }: SearchParamProps) => { const { userId } = auth(); const transformation = transformationTypes[type];

if (!userId) { redirect('/sign-in');

}

let user = null; try { user = await getUserById(userId); } catch (error) {

console.error('Error fetching user:', error);
// Optionally render an error UI or return a custom error component
return (
  <div>
    <p>There was an error loading the user data.</p>
  </div>
);

}

return ( <>

  <TransformationForm
    action="Add"
    userId={user._id}
    type={transformation.type as TransformationTypeKey}
    creditBalance={user.creditBalance}
  />
</>

); };

export default AddTransformationTypePage;

to detect errors then: image

then it shows this