t
tRPC
route needs jwt but it doesn't - tRPC
L
tRPC
•
3y ago
•
2 replies
lambo
route needs jwt but it doesn't
hi i do have a public route but when i i call it on the front end it requires a jwt token
SERVER
import
{ publicProcedure
, router
} from
'
.
.
/
.
.
/routes
/trpc
-init
-route
'
;
import
{ createUserSchema
} from
'
.
/users
.schema
'
;
import
{ createUserHandler
, getUserHandler
} from
'
.
/users
.controller
'
;
export const usersRouter
= router
(
{
helloUser
: publicProcedure
.query
(
(
)
=
>
{
return
{
data
:
'hello world
!
!
!
'
}
}
)
,
createUser
: publicProcedure
.input
(createUserSchema
)
.mutation
(
(
{ input
}
)
=
> createUserHandler
(
{ input
}
)
)
,
getUser
: publicProcedure
.input
(createUserSchema
)
.mutation
(
(
{ input
}
)
=
> getUserHandler
(
{ input
}
)
)
,
}
)
;
export type UsersRouter
= typeof usersRouter
;
CLIENT
export const setToken
=
(newToken
: string
)
=
>
{
token
= newToken
;
}
;
export const trpc
= createTRPCReact
<AppRouter
>
(
)
;
export const queryClient
= new QueryClient
(
)
;
export const trpcClient
= trpc
.createClient
(
{
links
:
[
httpBatchLink
(
{
url
:
'
http://localhost:4040/trpc
'
,
async headers
(
)
{
return
{
authorization
: token
}
}
}
)
,
]
}
)
tRPC
Join
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
4,951
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Recent Announcements
Similar Threads
Was this page helpful?
Yes
No
Similar Threads
can't call nested route
M
marcos daniel / ❓-help
3y ago
tRPC doesn't support redirect
B
backbone / ❓-help
4y ago
createTRPCOptionsProxy needs a queryClient?
A
Aleksander / ❓-help
6mo ago