Repository navigation
Closed
Labels
✅ accepted-PRs-welcomeFeature proposal is accepted and ready to work on
Description
Describe the feature you'd like to request
I have an authentication scheme that is based on signing the operation with a private key and verifying that with a public key. This is easy to do with httpLink because the function for creating headers is supplied with the operation.
const client = createTRPCClient<AppRouter>({
links: [
httpLink({
url: apiUrl,
headers: async (op) => {
const signature = await signRequest(op.input, op.path, op.type);
return {
'x-signature': signature
};
}
})
]
});I would like to do the same to authenticate the httpSubscriptionLink with connection options:
const client = createTRPCClient<AppRouter>({
links: [
splitLink({
condition: op => op.type === 'subscription',
true: unstable_httpSubscriptionLink({
url: apiUrl,
eventSourceOptions: async () => {
// no operation is supplied so no per request options
return { headers: {} }
}
}),
false: httpLink({
url: apiUrl,
headers: async ({op}) => {
const signature = await signRequest(op.input, op.path, op.type);
return {
'x-signature': signature
};
}
})
})
]
});Describe the solution you'd like to see
I would like for the operation that starts the event source to be passed into the function, very much like httpLink.
const client = createTRPCClient<AppRouter>({
links: [
unstable_httpSubscriptionLink({
url: apiUrl,
eventSourceOptions: async ({op}) => {
const signature = await signRequest(op.input, op.path, op.type);
return {
headers: {
'x-signature': signature
}
};
}
})
]
});Describe alternate solutions
- I have experimented with doing this as a link but unfortunately that doesn't expose the eventSourceOptions.
Additional information
I've done a quick implementation and it doesn't break any tests but this is my first contribution so take that with a grain of salt! I tried to port this to wsLink but because that doesn't have a one operation to one connection model, I don't think it makes sense.
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR implementing this feature!
Metadata
Metadata
Assignees
Labels
✅ accepted-PRs-welcomeFeature proposal is accepted and ready to work on
Activity
github-actions commentedon Oct 30, 2024
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.