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
1.07k stars 337 forks source link

User not found #25

Closed aryanjotwani closed 3 months ago

aryanjotwani commented 3 months ago

Unable to create users in the database.

Unhandled Runtime Error Error: Error: User not found

Source lib\utils.ts (18:11) @ handleError

16 | // This is a native JavaScript error (e.g., TypeError, RangeError) 17 | console.error(error.message);

18 | throw new Error(Error: ${error.message}); | ^ 19 | } else if (typeof error === "string") { 20 | // This is a string error message 21 | console.error(error);

atilla-the-hun commented 3 months ago

Running into this same error. My app worked fine before, now I get this. Anyone found an answer to this?

aryanjotwani commented 3 months ago

use this middleware.ts it worked for me.

import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";

const isPublicRoute = createRouteMatcher([ "/sign-in(.)", "/sign-up(.)", "/api/webhooks(.*)", "/", "/api/webhooks/clerk", "/api/webhooks/stripe" ]);

export default clerkMiddleware((auth, request) => { if (!isPublicRoute(request)) { auth().protect(); } });

export const config = { matcher: ["/((?!.\..|_next).)", "/", "/(api|trpc)(.)"], };