Brenner
Brenner
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Web Dev Cody on 1/28/2023 in #questions
Getting ts-jest to work with testing files that use the .env mjs files
+1 I'd like to know the answer to this too
10 replies
TTCTheo's Typesafe Cult
Created by Brenner on 1/29/2023 in #questions
New NodeError (looping error)
adding that code freezes my entire app
4 replies
TTCTheo's Typesafe Cult
Created by Brenner on 1/29/2023 in #questions
New NodeError (looping error)
this code is causing a problem:
if (error?.name === 'AirtableAuthError') {
// dont retry,
return false
}
if (error?.name === 'AirtableAuthError') {
// dont retry,
return false
}
4 replies
TTCTheo's Typesafe Cult
Created by Brenner on 1/29/2023 in #questions
New NodeError (looping error)
This is happening when I add code to my trpc code. as an example:
import { getAccessToken } from '@privy-io/react-auth'
import { httpBatchLink, loggerLink, TRPCClientError } from '@trpc/client'
import { createTRPCNext } from '@trpc/next'
import { type inferRouterInputs, type inferRouterOutputs } from '@trpc/server'
import { getNetwork } from '@wagmi/core'
import Router from 'next/router'
import { type AppRouter } from 'server/trpc/router/_app'
import superjson from 'superjson'

const getBaseUrl = () => {
if (typeof window !== 'undefined') return '' // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}` // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}` // dev SSR should use localhost
}

const getSlugs = (): Record<string, string | undefined> => {
if (typeof window === 'undefined') return {}
const path = window.location.pathname

const projectRegex = new RegExp(`project\/([^\/]+)(?:\/|$)`)
const projectslug = path.match(projectRegex)?.[1]

const orgRegex = new RegExp(`org\/([^\/]+)(?:\/|$)`)
const orgslug = path.match(orgRegex)?.[1]

return { projectslug, orgslug }
}

const getChain = (): string => {
if (typeof window === 'undefined') return 'undefined'
const { chain } = getNetwork()
// console.log('chain', chain)
return chain?.network ?? 'undefined'
}

// const getNetwork = async () => {
// if (typeof window === 'undefined') return ''
// const chainId = await window.ethereum.request({ method: 'eth_chainId' })
// return chainId // returns as 0x5
// }

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`,
async headers() {
const accessToken = await getAccessToken()
const slugs = getSlugs()
const chain = getChain()
// console.log('chain2: ', chain)
// const network = await getNetwork()
return {
Authorization: `Bearer ${accessToken}`,
...slugs,
chain,
}
},
}),
],
queryClientConfig: {
defaultOptions: {
queries: {
retry: (failureCount, error) => {
const rerouteCodes = ['UNAUTHORIZED', 'NOT_FOUND', 'FORBIDDEN']

if (error instanceof TRPCClientError) {
if (rerouteCodes.includes(error.data.code)) Router.push('/')
}

if (error?.name === 'AirtableAuthError') {
// dont retry,
return false
}
// console.log('failureCount', failureCount)
return failureCount < 3
},
},
},
},
}
},
ssr: false,
})

/**
* Inference helper for inputs
* @example type HelloInput = RouterInputs['example']['hello']
**/
export type RouterInputs = inferRouterInputs<AppRouter>
/**
* Inference helper for outputs
* @example type HelloOutput = RouterOutputs['example']['hello']
**/
export type RouterOutputs = inferRouterOutputs<AppRouter>
import { getAccessToken } from '@privy-io/react-auth'
import { httpBatchLink, loggerLink, TRPCClientError } from '@trpc/client'
import { createTRPCNext } from '@trpc/next'
import { type inferRouterInputs, type inferRouterOutputs } from '@trpc/server'
import { getNetwork } from '@wagmi/core'
import Router from 'next/router'
import { type AppRouter } from 'server/trpc/router/_app'
import superjson from 'superjson'

const getBaseUrl = () => {
if (typeof window !== 'undefined') return '' // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}` // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}` // dev SSR should use localhost
}

const getSlugs = (): Record<string, string | undefined> => {
if (typeof window === 'undefined') return {}
const path = window.location.pathname

const projectRegex = new RegExp(`project\/([^\/]+)(?:\/|$)`)
const projectslug = path.match(projectRegex)?.[1]

const orgRegex = new RegExp(`org\/([^\/]+)(?:\/|$)`)
const orgslug = path.match(orgRegex)?.[1]

return { projectslug, orgslug }
}

const getChain = (): string => {
if (typeof window === 'undefined') return 'undefined'
const { chain } = getNetwork()
// console.log('chain', chain)
return chain?.network ?? 'undefined'
}

// const getNetwork = async () => {
// if (typeof window === 'undefined') return ''
// const chainId = await window.ethereum.request({ method: 'eth_chainId' })
// return chainId // returns as 0x5
// }

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`,
async headers() {
const accessToken = await getAccessToken()
const slugs = getSlugs()
const chain = getChain()
// console.log('chain2: ', chain)
// const network = await getNetwork()
return {
Authorization: `Bearer ${accessToken}`,
...slugs,
chain,
}
},
}),
],
queryClientConfig: {
defaultOptions: {
queries: {
retry: (failureCount, error) => {
const rerouteCodes = ['UNAUTHORIZED', 'NOT_FOUND', 'FORBIDDEN']

if (error instanceof TRPCClientError) {
if (rerouteCodes.includes(error.data.code)) Router.push('/')
}

if (error?.name === 'AirtableAuthError') {
// dont retry,
return false
}
// console.log('failureCount', failureCount)
return failureCount < 3
},
},
},
},
}
},
ssr: false,
})

/**
* Inference helper for inputs
* @example type HelloInput = RouterInputs['example']['hello']
**/
export type RouterInputs = inferRouterInputs<AppRouter>
/**
* Inference helper for outputs
* @example type HelloOutput = RouterOutputs['example']['hello']
**/
export type RouterOutputs = inferRouterOutputs<AppRouter>
4 replies
TTCTheo's Typesafe Cult
Created by danmrkw on 1/29/2023 in #questions
trpc query only once parameter is not null
use the enabled: !!sessionData option
10 replies
TTCTheo's Typesafe Cult
Created by Brenner on 1/9/2023 in #questions
Tailwind Default Colors not showing automatically
The default colors aren’t showing up at all
7 replies