ai_saas_app icon indicating copy to clipboard operation
ai_saas_app copied to clipboard

User data collection is not creating in mongodb

Open adarshchhetri9 opened this issue 1 year ago • 14 comments

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

adarshchhetri9 avatar Mar 03 '24 15:03 adarshchhetri9

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

MusaMasroor avatar Mar 06 '24 23:03 MusaMasroor

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.

Satora1 avatar Mar 09 '24 15:03 Satora1

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 !

lounes213 avatar Mar 16 '24 14:03 lounes213

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 :(

alphaabhi avatar Mar 27 '24 21:03 alphaabhi

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.

Manubenakal avatar Apr 03 '24 06:04 Manubenakal

[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

abidhumza avatar Apr 04 '24 00:04 abidhumza

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

lounes213 avatar Apr 05 '24 15:04 lounes213

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

saadazghour avatar Apr 10 '24 01:04 saadazghour

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

Teegreat avatar Apr 28 '24 06:04 Teegreat

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?

AnshAtreja avatar May 05 '24 16:05 AnshAtreja

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?

yashchavda0 avatar May 12 '24 04:05 yashchavda0

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,
  },

lightcompass avatar Jun 23 '24 13:06 lightcompass

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

Swapnanil44 avatar Jul 10 '24 09:07 Swapnanil44

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 ?

rishisen0093 avatar Sep 09 '24 08:09 rishisen0093

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

khadeem100 avatar Oct 16 '24 14:10 khadeem100

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?

Swapnanil44 avatar Oct 16 '24 15:10 Swapnanil44

@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

lightcompass avatar Oct 16 '24 16:10 lightcompass