trpc first callH
Hi there! I'm trying to create my first trpc route, trying to copy the example route
1. Define a router in
src/server/trpc/router/route_name
;
2. Import and register the router in src/tprc/router/_app
3. import the router into the component from src/utils/trpc";
4. Call the registered route
1, url router
2. _app
3. component
4. ERROR in the component
Any idea why im getting this error? is urls not registered correctly or?74 Replies
looks like the route is importing correctly
You have input on your router but you are not passing any input when you are calling it
like this right?
Thank you @rocawear
On your server return "running create url" and on your call log the result
im feeling that's the error too but cant figure out how to call it
same error
You have to write the component differently
never gets to the retun statement (or the console log)
trpc creates hooks
you than have to use
useMutation
and .mutate()
on the hookooo?
Above the
oSubmit
function write:
and use the mutate function in onSubmit
methodSnippet from my project:
You need to use useQuery instead since you are not mutating
don't use query
change api
But since you should mutate you should change your query to mutate
from .query to .mutation
exactly
https://github.com/ruhap/t3-credentials/blob/main/src/components/form/RegisterForm.tsx I drop this here if it helps you
BOOOM
š„
thank you!
Lets go š !
gl with your project š„
thank you!
hey one more question while ive got you guys
this public procedure doesnt check auth
and there's a private procedure that does, is that correct?
yes, you should have procedure called
protectedProcedure
or sth like that
it gets session from next authboom
awesome thank you!
it also assigns your session to
ctx.session
if I'm not mistakenyes its there
and you can use it to get info of your authed user
and prisma is there
commiting!
nice, gl š
cheers mate
ok im back! wtf! the ssession.user doesn't have an id?
@Piotrek is this default? does it get stripped somewhere by ct3a?
it should have one, it's assigned in here:
https://create.t3.gg/en/usage/next-auth#inclusion-of-userid-on-the-session
Create T3 App
NextAuth.js š Create T3 App
The best way to start a full-stack, typesafe Next.js app.
see if you have this code
there's a small chance you used older version of ct3a by not adding
@latest
when initializing it, but most of the versions had the id inclusion anyway so idki dont think i do
it's not in trpc
it's inside of the next auth handler
just add that file
where do you have your nextAuth initializer?
config*?
this one?
yep
go there
and check for the session callback
looks like its there
and it's on the ytpe
type
why is your callbacks underlined? what's the error?
but its not there in the trpc Router
is there a way to show the whole thing in vscode?
what thing?
the whole error
i'm not sure
does this answer that question? what is the callbacks error?
it seems like it has to be
token.id as string
not user.id
š¤·āāļø
maybe there was some change in nextAuth
or you're using jwtActually no, I am using jwt. Sorry
Bad example
@fotoflo are you using jwt there?
or default config
no im using prisma
With discord auth?
i dopped a debugger on that session callback and logged in and out and it didnt stop at the breakpoint
@rocawear i have that code in my session callback already
...
oh
i have something dumb in there
lol
i had the callbacks property defined twice
oops
resolved
tahnk you ... i dumb
but now i know how this works
thank you @Piotrek and @rocawear !