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.13k stars 356 forks source link

User data collection is not creating in mongodb #12

Open adarshchhetri9 opened 8 months ago

adarshchhetri9 commented 8 months ago

Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received

MusaMasroor commented 8 months ago

could you provide more context about the problem you're facing.

Satora1 commented 8 months ago

By checking the Vercel logs, I managed to locate the issue. It turned out that I didn't pass the WEBHOOK_SECRET variable in Vercel, and I also failed to update the webhook URL after restarting the server in Vercel. I fixed these errors, and now everything is working correctly.

lounes213 commented 8 months ago

i have problem with Sync Clerk data my webhooks show failed requests but on my cluster db the User Db is created with out data sync. thank you !

alphaabhi commented 7 months ago

I am unable to see the user data for the users I am logging within my mongoDb database. I have deployed everything correctly, even rechecked everything from MongoDb Url to webhook URL in my versel but I cannot just seem to figure out why can't I see the data of users logged in through userCreation in my MongoDb database. If anybody could help out please , I don't want to get stuck after almost halfway through :(

Manubenakal commented 7 months ago

if the user is not being created inside the database, then you need to check whether you're running your app on local host or Vercel. The webhook secret key (Clerk) works when you host your app on Vercel. Go to clerk dashboard -> web hooks -> end points -> https://my-app.vercel.app/api/webhooks/clerk. make sure to host your app on vercel before creating this endpoint. after that try creating an account on imaginfy hosted at https://my-app.vercel.app/ .if you try to create an account on imaganify while running it on local host, the web hook won't work and the user created on clerk dashboard will not be stored inside mongo Db. hence causing the user not found error.

abidhumza commented 7 months ago

[GET] [middleware: "middleware"] / status=307 When running on production env, getting this error. Also getting this error log. I followed the same as shown in the video, tried all the options still dont understand what i am missing.

INFO: Clerk: The request to / is being redirected because there is no signed-in user, and the path is not included in ignoredRoutes or publicRoutes. To prevent this behavior, choose one of:

  1. To make the route accessible to both signed in and signed out users, add "/" to the publicRoutes array passed to authMiddleware
  2. To prevent Clerk authentication from running at all, pass ignoredRoutes: ["/((?!api|trpc))(_next.*|.+\.[\w]+$)", "/"] to authMiddleware
  3. Pass a custom afterAuth to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes

For additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware (This log only appears in development mode, or if debug: true is passed to authMiddleware) INFO: Clerk: The request to / is being redirected because there is no signed-in user, and the path is not included in ignoredRoutes or publicRoutes. To prevent this behavior, choose one of:

  1. To make the route accessible to both signed in and signed out users, add "/" to the publicRoutes array passed to authMiddleware
  2. To prevent Clerk authentication from running at all, pass ignoredRoutes: ["/((?!api|trpc))(_next.*|.+\.[\w]+$)", "/"] to authMiddleware
  3. Pass a custom afterAuth to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes
lounes213 commented 7 months ago

thank you ! it work only on hosted app not on localhost

saadazghour commented 7 months ago

Same things it's work only on hosted app @lounes213

Teegreat commented 6 months ago

The issue is coming from MongoDB as the application cannot access the database based on the IP address captured during the setup process of your DB. To fix this issue;

  1. Login to MongoDB
  2. Navigate to the Network Access Tab
  3. Delete all IP addresses listed
  4. Click on Add IP Addresses >> Add your current IP address
  5. Again, click on Add IP Addresses, this time you are to allow access from anywhere by simply typing this: 0.0.0.0/0
AnshAtreja commented 6 months ago

thank you ! it work only on hosted app not on localhost

@lounes213 in the video at 1:38:00, in localhost I could not see any user database being added, does it only show on the deployed version?

yashchavda0 commented 6 months ago

if the user is not being created inside the database, then you need to check whether you're running your app on local host or Vercel. The webhook secret key (Clerk) works when you host your app on Vercel. Go to clerk dashboard -> web hooks -> end points -> https://my-app.vercel.app/api/webhooks/clerk. make sure to host your app on vercel before creating this endpoint. after that try creating an account on imaginfy hosted at https://my-app.vercel.app/ .if you try to create an account on imaganify while running it on local host, the web hook won't work and the user created on clerk dashboard will not be stored inside mongo Db. hence causing the user not found error.

it isn`t working for me. Do you have any other way to solve the problem?

lightcompass commented 4 months ago

Hi, I encountered the same, but after debugging, I found the response from the clerk over Google Oauth is changed, there is no "username" and "photo" attribute.

at the codebase please look at the user model, it requires these 2 attributes to create a user.

my hotfix is to remove the "require" attribute, so my user.model.ts look like below

userName: {
    type: String,
  },
  photo: {
    type: String,
  },
Swapnanil44 commented 4 months ago

Hi, I encountered the same, but after debugging, I found the response from the clerk over Google Oauth is changed, there is no "username" and "photo" attribute.

at the codebase please look at the user model, it requires these 2 attributes to create a user.

my hotfix is to remove the "require" attribute, so my user.model.ts look like below

userName: {
    type: String,
  },
  photo: {
    type: String,
  },

Thanks man, this solved my issue

rishisen0093 commented 2 months ago

Hi, I encountered the same, but after debugging, I found the response from the clerk over Google Oauth is changed, there is no "username" and "photo" attribute. at the codebase please look at the user model, it requires these 2 attributes to create a user. my hotfix is to remove the "require" attribute, so my user.model.ts look like below

userName: {
    type: String,
  },
  photo: {
    type: String,
  },

Thanks man, this solved my issue

Hi, I encountered the same, but after debugging, I found the response from the clerk over Google Oauth is changed, there is no "username" and "photo" attribute. at the codebase please look at the user model, it requires these 2 attributes to create a user. my hotfix is to remove the "require" attribute, so my user.model.ts look like below

userName: {
    type: String,
  },
  photo: {
    type: String,
  },

Thanks man, this solved my issue

were you able to solved the issue and complete the project ?

khadeem100 commented 1 month ago

the isssue lies in the clerk configuration you need to have username enabled to aunthenticate the user the right way

Swapnanil44 commented 1 month ago

the isssue lies in the clerk configuration you need to have username enabled to aunthenticate the user the right way

can you please elaborate the right way?

lightcompass commented 1 month ago

@khadeem100 is correct, you don't need to change the code.

go to clerk setting, and enable username is require overthere then all should be good

ref: https://clerk.com/docs/authentication/configuration/sign-up-sign-in-options