Mugetsu
Mugetsu
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Mugetsu on 10/2/2024 in #questions
tRPC mutation onError handler error type for shared logic
Thanks ! Yeah i needed to assert the error type inside the handler and make error param of unknow type
5 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
Use Zod schema after parse & transform as a new schema
Thanks @Jacob it helped me a lot with ur suggestions!
7 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/9/2024 in #questions
New Zod schema based on an existing one, with some fields having different validation rules?
Well it seems to be working. Extend here seems better choice after playing with it as it need less z props through out. Thank you for suggestion ! ❤️
5 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
Use Zod schema after parse & transform as a new schema
@Jacob yes, exactly.
7 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
typescript object util library
Particularly I need to flatten keys of deeply nested objects to strings and being able to set/get/pick via string keys
9 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 9/3/2024 in #questions
typescript object util library
Doesn’t seem like accessing object via “property.x.b.c” is basic language stuff. My question might be misleading a little bit. I was referring to string dot notation keys. Sorry
9 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 8/28/2024 in #questions
Use ReactQuery to fetch different api resource than trpc resource
Yeah. Exactly what I found just after posting the question 🤦‍♂️ nonetheless thanks for answering as its what I was asking for ! Thank you ❤️
5 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 1/9/2024 in #questions
Logging trpc errors in production
P.S. Im using custom PINO logger and not deploying to vercel
4 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 11/30/2023 in #questions
TRPC Server error handling?
my apology. Out of habit 🤦‍♂️
6 replies
TTCTheo's Typesafe Cult
Created by hyhy on 9/20/2023 in #questions
Refreshing NextAuth Discord provider user details
Sweet, thanks ! 😉
15 replies
TTCTheo's Typesafe Cult
Created by hyhy on 9/20/2023 in #questions
Refreshing NextAuth Discord provider user details
Hey, whats is this theme ? 😉
15 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 7/12/2023 in #questions
NextJs 13 app folder - SPA
Yes thats correct. React router v3.2.0🙅‍♂️. Remix is not an option. Im torn between switching to vite build or next app dir. But I'm not sure because I'm reading a lot of bad stuff on app dir right now. I want simple setup/configuration and a low entry point so i can focus on rewriting page by page for the new app asap with the possibility of future-proofing and ease of maintenance.
5 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 12/21/2022 in #questions
tRPC query | mutation Error Boundary catch
@Mik3y-F It turns out that the React version for me is the problem. I still use old one 16.8.6 and on 18.2.0 it works as expected
6 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 12/21/2022 in #questions
tRPC query | mutation Error Boundary catch
@Mik3y-F not yet. I was on holiday and will look into this/next week. I reported this also to trpc as an issue and they need some reproduction of issue. If you have some fairly simple setup of the project and could share it as a reproduction it could help track whats wrong. I have private repo which i need to strip down greatly before i could share (not sure if i will be able to). https://github.com/trpc/trpc/issues/3447
6 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 11/27/2022 in #questions
Good courses recommendations
I was just wondering if there is something around to extend experience and knowledge is paid and in general recommended
16 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 11/27/2022 in #questions
Good courses recommendations
Yeah I cant spend it on anything i like. It has to be educational course.
16 replies
TTCTheo's Typesafe Cult
Created by WOLFLEADER on 11/9/2022 in #questions
Learning a functional lang
You might look into https://github.com/mobily/ts-belt instead of fp-ts but thats just my prefference
14 replies
TTCTheo's Typesafe Cult
Created by Froxx on 11/6/2022 in #questions
Handle specific tRPC errors centrally
I do something like this.
// src/utils/trpc.ts
import superjson from "superjson";

import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import type { GetInferenceHelpers } from "@trpc/server";

import type { AppRouter } from "@/server/trpc/router/_app";
import { QueryCache } from "@tanstack/react-query";
import { signOut } from "next-auth/react";

const getBaseUrl = () => {
if (typeof window !== "undefined")
return process.env.NEXT_PUBLIC_APP_BASE_PATH; // browser should use relative url

if (process.env.VERCEL_URL)
return `https://${process.env.VERCEL_URL}${process.env.APP_BASE_PATH}`; // SSR should use vercel url

return `http://localhost:${process.env.PORT ?? 3000}${
process.env.APP_BASE_PATH
}`; // dev SSR should use localhost
};

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,
refetchOnWindowFocus: false,
refetchOnMount: false,
},
},
queryCache: new QueryCache({
onError: async (error: any) => {
if (error.message === "UNAUTHORIZED") {
await signOut();
}
},
}),
},
};
},
ssr: false,
});

/**
* Inference helpers
* @example type HelloOutput = AppRouterTypes['example']['hello']['output']
**/
export type AppRouterTypes = GetInferenceHelpers<AppRouter>;
// src/utils/trpc.ts
import superjson from "superjson";

import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import type { GetInferenceHelpers } from "@trpc/server";

import type { AppRouter } from "@/server/trpc/router/_app";
import { QueryCache } from "@tanstack/react-query";
import { signOut } from "next-auth/react";

const getBaseUrl = () => {
if (typeof window !== "undefined")
return process.env.NEXT_PUBLIC_APP_BASE_PATH; // browser should use relative url

if (process.env.VERCEL_URL)
return `https://${process.env.VERCEL_URL}${process.env.APP_BASE_PATH}`; // SSR should use vercel url

return `http://localhost:${process.env.PORT ?? 3000}${
process.env.APP_BASE_PATH
}`; // dev SSR should use localhost
};

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,
refetchOnWindowFocus: false,
refetchOnMount: false,
},
},
queryCache: new QueryCache({
onError: async (error: any) => {
if (error.message === "UNAUTHORIZED") {
await signOut();
}
},
}),
},
};
},
ssr: false,
});

/**
* Inference helpers
* @example type HelloOutput = AppRouterTypes['example']['hello']['output']
**/
export type AppRouterTypes = GetInferenceHelpers<AppRouter>;
13 replies
TTCTheo's Typesafe Cult
Created by Mugetsu on 10/20/2022 in #questions
Next-Auth types
Silly me.. this works
signIn ({ profile }) {
if (!profile) return false;

const { groups = [] } = profile;

return groups.some(Boolean);
},
signIn ({ profile }) {
if (!profile) return false;

const { groups = [] } = profile;

return groups.some(Boolean);
},
3 replies