Next.js Discord

Discord Forum

data not sending in mongodb

Answered
rkstlohchab posted this in #help-forum
Open in Discord
i tried add
string | null

to Params but still it didnt worked well ,
i used clerk to send the user data > to server action > then database
but it didnt worked
@Clown @"use php"
Answered by "use php"
Summary:
- The issue was caused due to middleware
- Further, it was caused due to fact Clerk was not providing firstname & lastname
View full answer

387 Replies

yeah
it is saying
string canot be assigned to
string | null
in firstName, add string | null
@"use php" in firstName, add `string | null`
i did
still it is not working
@"use php" in firstName, add `string | null`
the error goes away but
the user is not
passed on to
db
the event was fired at the api endpoint
that basically means that you can't get first_user to be null
means you'll have to verify if first_user has a value
i tried this
@"use php" means you'll have to verify if first_user has a value
the code worked but the data is not in db still
Console log response from mongodb
@rkstlohchab Click to see attachment
A suggestion, you can just use .toObject function to convert to object
Send console log of new user
there is no log
i think the data is not passed through
In catch error just console.error(error)
scroll up to the error
if you want, you can give vscode share link
what to do to reproduce err
@rkstlohchab
@"use php" what to do to reproduce err
remove the exclamation mark
!
from the
route.ts file
I fixed the warning
Just customise the response message later on
like in json if needed
and what action to do to check webhook?
@rkstlohchab
what bro?
@"use php" I fixed the warning
what did u do
?
@rkstlohchab what did u do
how to check the
webhook event
right?
yes, you said item was not getting added to db
wait that can only be accessed on deployed version
lemme check
endpoint
for webhook event
that works well on deployed version
wait 1 min
ohk
production error
logs
Also view clerk
in message attempts
?
Send production logs
are you sure the latest version is deployed?
yes
i just deployed 4 mins ago
Can you first use https://smee.io/ to test webhook locally?
what exactly is this used for i didnt quite understood
You can use it to test webhook locally
so the
webhook
from
clerk
can be used
in localhost
not staright in production build
right?
yes
now what do i have to do to get the webhook
should i setup
yes
smee / api/webhook
in my clerk
?
target should be http://localhost:3000/api/webhook
bro just to be clear i want to ask
http://localhost:3000/api/webhook

i should setup this in my clerk dashboard or in the smee terminal?
In clerk dashboard
it should be the url on the page
in clerk
webhook uri
we can not add local host directly in clerk i mentioned that earlier
I mean
the url
like this ?
i really dont understand what u want to say
...
I'll give you a webhook url, just set it to that
rest I'll setup
done
can you try now
do a request now
do the same in clerk
@"use php" https://smee.io/4KpGJSHF4V1UsqJD
In clerk, set it to this
okay
wait
i added this
to clear
clerk
and also updated the env file for webhook secret
can you try giving a request now?
the data is paased on to
smee
was the user created?
yes
user was created
and the
webhook was fired at
smee
at this url
but it wasnt updated in db
wait lemme see
can you CTRL+C the terminal where you ran smee?
i did
wait don't' run again
ohkky
wait a min
now try
try runnin smee
or
old
api/webhook route
I ran in my system
wait 1 min, I think there is some bug with code or somethin
there is a 404 error in development also
yea
you can see the app terminal
that
is currently maybe because
of the smme
no
we are using smee currently
I tried using fetch api locally also
still error
Can you try restarting next app
i did
just now
2 3 mins ago
when u said
ctrl c smee
restarted again
Its because of middleware.ts
its a ignored route
it wasnt before
i added it
to check
i removed it
now
should i deploy and test again ?
oh wait
if they are ignored route
just add it back
i see what you did wrong
I'll fix it
@"use php" i see what you did wrong
whats that
wait I'm confused
should we ask moderator?
no
@rkstlohchab don't ping moderator
okay
so @rkstlohchab its some bug with the middleware only
ohh
I added /api/webhook in public Route
not sure if its supposed to be there, just confirm once
Can you try sending request now?
shit i just saw
i added
/api/webhooks
but its
/api/webhook
try sending request
in clerk
damn
lemme try brother
so lame of me
well
the object was created in db
thats a good start
but there is no data
can you try now?
can you set webhook url to smee url?
if not ady
wait
done
check
make q req
@"use php" make q req
u can also do that by creating deleting updating user
ok
yepp
it captures all
event
we are at 220+ messages. please wrap things up soon.
alright
@joulev we are at 220+ messages. please wrap things up soon.
we are trying our best
if u can help we would be happy to accept it
@"use php" how can you send data to db using smee ?
you can't
smee is just like a proxy
to see that if the webhook is giving data
right
it is passing data to smee
I'm not sure why clerk is sending a webhook to delete data
but not on my webhook
i also tried
deleting
user
don't try for now
my user accnt
@"use php" don't try for now
okay
it is passing
i thinkg
null data
thats why it is not getting updated on db
check terminal
clerk is not giving a first name & last name
that you'll have to fix
wait lemme check
i enabled that
it was disabled by default
previously
it used to be enabled
let it be disabled for now
You can add it later on
this was enabled previously
in updated they changed it again
update it later on
🫠
@"use php" update it later on
sure
check the data @rkstlohchab
database
listen
give me
5 minutes
i think now i can do it
ok
i dont know what is wrong with the code now
i enabled clerk firstname lasstname
it should work just fine now
ok
the webhook url is still that url, right?
the smee one
the deleted url is passed
to the
to my deployed version
but create is not passed
I'm not sure what you mean
I'll test it out
@"use php" the webhook url is still that url, right?
now i changed it to
deplyed site
done
first name and last name is optional fyi
it impports data
with
the sign in from google
alright
first name and lastname arent option
check database?
asking for them
is option
weather u want to as users
or not
@"use php" check database?
wait
it worked
finally
but it is not working for my endpoint
why is that
Check env
check vercel logs
vercel log also succes
first 2 is smee logs
after creating user
you probably didn't update the env for webhook
svix-id and all
timestamp, signature
if i didnt updated env
then ur smee wouldnt have worked
lemme tell u
for example the
you updated in production
secret key currently is
xyz
just example
dont reveal it
xyz
its not
this just example
can you try pushing now, and just check?
xyz is on local host and on vercel deployement
i changed the webhook url for tha same
xyz key
in clerk
getting ?
code
it'll console.log the error then
wait
first i have to change the url
for webhook
change to prod
failed again
vercel log
did you add a first name?
that indicates data is missin
did u logged in using gmail or manual data
gyou can see above the request on webhook logo
@rkstlohchab did u logged in using gmail or manual data
I logged in using manual data
wait
i logged in using
google
that may be problem
@"use php" vercel log
Above this, on the second log
see
you'll see
first_name is null
@"use php" see
yea
so should I make it optional then
or you can make it optional
it worked
woah
data is in the db
now
i ll break the code again
dont forget to update params and model
done
wait model
done
ohkaaay buddy
Summary:
- The issue was caused due to middleware
- Further, it was caused due to fact Clerk was not providing firstname & lastname
Answer
you got the option now, nice
yesss
😂
i updated dc
oh alright
You can also [sponsor me](https://github.com/sponsors/anay-208/) for my efforts
Let me know if you have any other issue!
ohkayy
i am also from india
alright
#off-topic
yepp