cha0sg0d
cha0sg0d
TtRPC
Created by cha0sg0d on 2/23/2024 in #❓-help
Subscription for a specific user
How can I create a TRPC subscription that takes a userId? When updates occur elsewhere in my app, I want to broadcast them to relevant users. Trying to avoid a full Socket.io rooms implementation
4 replies
TtRPC
Created by cha0sg0d on 2/6/2024 in #❓-help
How to get the type of context after middleware context extension?
I have a middleware where I validate and set a userId. My router knows that userId is no longer undefined, but I need to pass the route context to another function. How do I set the input type for that function such that userId is no longer undefined?
9 replies
TtRPC
Created by cha0sg0d on 2/2/2024 in #❓-help
Efficient way to use tRPC client with auth headers from secure storage
Wondering if anyone has a recommended pattern on caching the deviceId / authHeader using a React Context instead of fetching it async on each request. Thanks!
export const trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: getServerUrl(),
async headers() {
const authorization = await getAuthHeader()
const deviceId = await createOrGetDeviceIdFromStore()
return {
authorization,
'x-device-id': deviceId,
}
}
})
]
})
export const trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: getServerUrl(),
async headers() {
const authorization = await getAuthHeader()
const deviceId = await createOrGetDeviceIdFromStore()
return {
authorization,
'x-device-id': deviceId,
}
}
})
]
})
7 replies