rustclan
rustclan
Explore posts from servers
TTCTheo's Typesafe Cult
Created by rustclan on 9/3/2023 in #questions
TRPC error handling
Thank you 🙂
4 replies
TTCTheo's Typesafe Cult
Created by rustclan on 4/30/2023 in #questions
TRPC ratelimiting endpoints (race conditions)
bump
3 replies
TTCTheo's Typesafe Cult
Created by rustclan on 4/30/2023 in #questions
TRPC ratelimiting endpoints (race conditions)
function which needs to be ratelimited (using the redis cache)
export const getUserGuilds = async (
session: Session
): Promise<CachedUserGuild[] | null> => {
if (!session.user.accessToken || !session.user.id) return null;

const webUser = await cache.webUsers.get(session.user.id);
if (webUser) return webUser.guilds;

const response = await fetch(discord...)
const guilds = await response.json();
if (!response.ok || guilds.length <= 0) return null;

// add guilds to cache
await cache.webUsers.create(session.user.id, guilds);

return guilds;
};
export const getUserGuilds = async (
session: Session
): Promise<CachedUserGuild[] | null> => {
if (!session.user.accessToken || !session.user.id) return null;

const webUser = await cache.webUsers.get(session.user.id);
if (webUser) return webUser.guilds;

const response = await fetch(discord...)
const guilds = await response.json();
if (!response.ok || guilds.length <= 0) return null;

// add guilds to cache
await cache.webUsers.create(session.user.id, guilds);

return guilds;
};
A big band aid fix would be to just add an artificial wait:
if (!guilds) {
await new Promise((resolve) => setTimeout(resolve, 1000));
webUser = await cache.webUsers.get(ctx.session.user.id);
guilds = webUser?.guilds;
if (!guilds) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
}
if (!guilds) {
await new Promise((resolve) => setTimeout(resolve, 1000));
webUser = await cache.webUsers.get(ctx.session.user.id);
guilds = webUser?.guilds;
if (!guilds) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
}
But obviously this is not very elegant..
3 replies
TTCTheo's Typesafe Cult
Created by rustclan on 12/4/2022 in #questions
TRPC cache (with vercel, but not working locally too)
bump
2 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/30/2022 in #questions
TRPC max retries on endpoint
yep. I want to change global. Useful to know that i can change specific query tho. thanks!
15 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/30/2022 in #questions
TRPC max retries on endpoint
Thank you so much!
export const trpc = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
queryClientConfig: {
defaultOptions: {
queries: {
retry: false,
},
},
},
};
},
ssr: false,
});
export const trpc = createTRPCNext<AppRouter>({
config() {
return {
transformer: superjson,
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
queryClientConfig: {
defaultOptions: {
queries: {
retry: false,
},
},
},
};
},
ssr: false,
});
I had to insert queryClientConfig inside of this initaliser 🙂
15 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/30/2022 in #questions
TRPC max retries on endpoint
I'm looking for where the rq/adapter is made and I cannot find where I can configure the queryclient. i ASSUME IT IS IN trpc.ts
const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape;
},
});
const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter({ shape }) {
return shape;
},
});
after looking at the trpc docs, it appears this is where it is intialized. But cannot find any information about adding custom reactquery options.
15 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/30/2022 in #questions
TRPC max retries on endpoint
oh right okay. Thank you 🙂
15 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/30/2022 in #questions
TRPC max retries on endpoint
oh apologies. I was not aware trpc used react query
15 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
You have saved me many hours
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
Np. I appreciate the help 🙂
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
Thanks! That fixes it. Sorry for that mistake 🙂
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
Alright yea, that resolves it.
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
ill try comment this out see if that resolves it.
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
Not that I know of. I'm trying to use env.NEXT_PUBLIC_CLIENT_INVITE_URL in a component. But this is a client env as far as I know.
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
# Next Auth
NEXTAUTH_SECRET="..."
NEXTAUTH_URL="http://localhost:3000"
# Next Auth
NEXTAUTH_SECRET="..."
NEXTAUTH_URL="http://localhost:3000"
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
Nope! Unfortunately still the same.
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
hmm. My database env is:
DATABASE_URL="mysql://root@localhost:3306/aio"
DATABASE_URL="mysql://root@localhost:3306/aio"
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
me too! 😛
27 replies
TTCTheo's Typesafe Cult
Created by rustclan on 11/20/2022 in #questions
invalid environment variables
correct, it has contents. It is a url example:
NEXT_PUBLIC_CLIENT_INVITE_URL="https://discord.com/api/oauth2/authorize"
NEXT_PUBLIC_CLIENT_INVITE_URL="https://discord.com/api/oauth2/authorize"
27 replies