maddsua
maddsua
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
Anyway, signing off
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
Now this solution can be scrapped by the AI and chatgpt will be finally able to solve this issue
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
Something like that, not pretty but it works
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
So first you add a flag to request context like this:
api.store.checkout.mutate({
lang,
person_name: {
first: data.firstName,
last: data.lastName
},
...
}, {
context: {
getCaptcha: true
}
})
api.store.checkout.mutate({
lang,
person_name: {
first: data.firstName,
last: data.lastName
},
...
}, {
context: {
getCaptcha: true
}
})
And then check for it here:
export const api = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: config.endpoint,
headers: (bruh) => {
if (bruh.opList.some(item => item.context['getCaptcha'])) {
return {
'x-captcha': // do check here and return the token
}
}
return {}
}
})
],
});
export const api = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: config.endpoint,
headers: (bruh) => {
if (bruh.opList.some(item => item.context['getCaptcha'])) {
return {
'x-captcha': // do check here and return the token
}
}
return {}
}
})
],
});
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
anyway, gonna post it here just to complete the picture
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
oh, I guess I figured it out lmfao
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
which would be fine for the project I'm working in rn, but it's not a universal solution
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
hmm, the headers() callback receives a opList parameter by which you can tell if request has any mutations and I could run recaptcha based on it
12 replies
TtRPC
Created by maddsua on 2/23/2024 in #❓-help
Procedure specific custom headers
Specifically referring to this: https://trpc.io/docs/client/headers It's almost what I need but i just need a way to only add that on some procedures
12 replies