Ryan
Ryan
Explore posts from servers
TtRPC
Created by Ryan on 9/28/2023 in #❓-help
Modify the payload before mutating
I wouldn't be losing type safety necessarily, cause the items that I want to add in preprocessing are all optional items, so mutate would still infer its original payload type This is what I ended up doing.. not sure I like it though, also not 100% sure what the impications of using the ProxyClient is on the cache, if any.
export const useVerifyCode = () => {
const key = getQueryKey(trpc.auth.verifyCode);

const mutationFn = async (block: RouterInputs['auth']['verifyCode']) => {
const maybeReferralCode = storage.getReferrerCode();
const maybeUTM = storage.getUTM();
const utmObject = maybeUTM ? JSON.parse(maybeUTM) : {};
// safe parse with zod
const utmValidation = zodUtm.safeParse(utmObject);
const validatedUtm = utmValidation.success ? utmValidation.data : {};

const extendedBlock = {
...block,
referralCode: maybeReferralCode,
...validatedUtm,
};

return trcpProxyClient.auth.verifyCode.mutate(extendedBlock);
};

const mutation = useMutation({
mutationFn,
mutationKey: key,
onSuccess(data) {
storage.setAccessToken(data.accessToken);
storage.setRefreshToken(data.refreshToken);

identify(data);
},
});

return mutation;
};
export const useVerifyCode = () => {
const key = getQueryKey(trpc.auth.verifyCode);

const mutationFn = async (block: RouterInputs['auth']['verifyCode']) => {
const maybeReferralCode = storage.getReferrerCode();
const maybeUTM = storage.getUTM();
const utmObject = maybeUTM ? JSON.parse(maybeUTM) : {};
// safe parse with zod
const utmValidation = zodUtm.safeParse(utmObject);
const validatedUtm = utmValidation.success ? utmValidation.data : {};

const extendedBlock = {
...block,
referralCode: maybeReferralCode,
...validatedUtm,
};

return trcpProxyClient.auth.verifyCode.mutate(extendedBlock);
};

const mutation = useMutation({
mutationFn,
mutationKey: key,
onSuccess(data) {
storage.setAccessToken(data.accessToken);
storage.setRefreshToken(data.refreshToken);

identify(data);
},
});

return mutation;
};
9 replies
TtRPC
Created by Ryan on 9/28/2023 in #❓-help
Modify the payload before mutating
I would but I would need to separately wrap both mutate and mutateAsync since I would need to modify the payload on both. Yeah I have a few more non utm param things, like referral code etc.
9 replies
TtRPC
Created by Ryan on 9/28/2023 in #❓-help
Modify the payload before mutating
I have a hook wrapped around this specific useMutation that is called from a few different places in my app. I need it to pass some UTM params stored in my local storage along with the payload, but don't want to have to remember to always include the params when I call the mutation. Ideally in the hook (within the mutate fn) I can add the utms
9 replies
TtRPC
Created by Ryan on 4/28/2023 in #❓-help
Can you return from an API endpoint before a sync operation is complete?
If you do - let me know how it is 🙂
34 replies
TtRPC
Created by Ryan on 4/28/2023 in #❓-help
Can you return from an API endpoint before a sync operation is complete?
I've never used this service before, so not a recommendation, but I came across this product that has a Vercel integration that maybe you could use @Tom3 https://vercel.com/integrations/serverlessq
34 replies
TtRPC
Created by Ryan on 4/28/2023 in #❓-help
Can you return from an API endpoint before a sync operation is complete?
Agreed, it's more so small cleanup things that I wanted to do, like after a user has claimed x delete it from the DB in a second call that doesn't effect what the user sees. But as most of these won't add significant time I will probably just await them for now until I have time to setup a job queue
34 replies
TtRPC
Created by Ryan on 4/28/2023 in #❓-help
Can you return from an API endpoint before a sync operation is complete?
fair point 🫡
34 replies
TtRPC
Created by Ryan on 4/28/2023 in #❓-help
Can you return from an API endpoint before a sync operation is complete?
Is there any way that you are aware of to handle this without adding the task to like a queue or something? @alex / KATT
34 replies
TtRPC
Created by Ryan on 4/28/2023 in #❓-help
Can you return from an API endpoint before a sync operation is complete?
Yeah I was running into this issue with tasks that were < 30s
34 replies
TtRPC
Created by dj0024javia on 4/28/2023 in #❓-help
JWT Token is type "never" in frontend.??!!
TS can't infer what type of data is in your JWT. You could use Zod to validate the fields you expect and then infer the type from Zod
4 replies