Domcario
Domcario
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Domcario on 12/27/2023 in #questions
in a t3 project, do i use trpc for 3rd party APIs?
for example, i want to use this endpoint for github's api https://docs.github.com/en/rest/metrics/statistics?apiVersion=2022-11-28#get-all-contributor-commit-activity should i be using trpc & making a router?
6 replies
TTCTheo's Typesafe Cult
Created by Domcario on 5/7/2023 in #questions
ct3a stack equivalent for iOS *native* apps
Thinking about spending a weekend learning swift/uikit for fun, but what’s the full stack equivalent of ct3a for iPhone? Hopefully the intent behind this question is clear.
2 replies
TTCTheo's Typesafe Cult
Created by Domcario on 4/27/2023 in #questions
how to use indexeddb with react query (dexie.js)
im working on a project that doesnt have a hosted database, everything is done locally. im using dexie.js as my indexeddb wrapper, and im wondering if/how i can use react query with indexeddb instead.
2 replies
TTCTheo's Typesafe Cult
Created by Domcario on 4/16/2023 in #questions
deno/supabase edge func: so many typescript lint errors
10 replies
TTCTheo's Typesafe Cult
Created by Domcario on 4/12/2023 in #questions
verify thought process: TS and python serverless functions
im making the backend for a chrome extension that downloads the mp4 audio file from a youtube video and runs it through the whisper api from openai i have a job queue table in my DB that tracks the status of jobs that are queued for 1. downloading audio from YT or 2. running audio through whisper i have a supabase edge function (deno so only TS is supported) that will download audio and save to supabase storage for the 2nd serverless function to run an audio file through whisper, im not sure how to tackle it since whisper is in python. should i make a vercel serverless function with python runtime? i was just playing around in a google colab python notebook to see if i could do everything (download audio, and run through whisper) all at once. so i know the code works when it's altogether, but this approach is splitting it up kind of noob, but want to learn. looking for some direction here
3 replies
TTCTheo's Typesafe Cult
Created by Domcario on 3/31/2023 in #questions
better supabase auth than with useEffect & getSession on each page?
apparently the way i was doing this was very noob, but not sure what the best alternative would be before i had a useEffect on each page in my webapp like this
useEffect(() => {
const getUser = async () => {
const {
data: { session },
} = await supabase.auth.getSession()

if (!session) {
console.log('no session')
} else if (!session.user) {
console.log('no user')
} else {
// console.log('session.user: ', session.user)
setUser(session.user)
}
}

void getUser()
}, [])
useEffect(() => {
const getUser = async () => {
const {
data: { session },
} = await supabase.auth.getSession()

if (!session) {
console.log('no session')
} else if (!session.user) {
console.log('no user')
} else {
// console.log('session.user: ', session.user)
setUser(session.user)
}
}

void getUser()
}, [])
apparently this is really bad, especially on each page. what should i be doing instead when using supabase auth? id like to have the session/user data and details available on every page without have the same useeffect call on every page
10 replies
TTCTheo's Typesafe Cult
Created by Domcario on 3/24/2023 in #questions
when to use tRPC vs a nextjs api route
ive really started to appreciate the tRPC-prisma data flow to my frontend, but im coming from a nextjs-not-typescript background. ive been using api routes there forever, and i still see it in the ct3a directory. but when do i use it then?
29 replies
TTCTheo's Typesafe Cult
Created by Domcario on 3/20/2023 in #questions
avoid rendering more hooks: running trpc query based on supabase session's user
i have a router workspace with query getWorkspace that takes the current supabase session's user's UUID id and returns details of the workspace they're a member of
export const workspaceRouter = createTRPCRouter({
getWorkspace: publicProcedure
.input(
z.object({
user_id: z.string(),
}),
)
.query(async ({ input, ctx }) => {
const prisma = new PrismaClient()
try {
await prisma.$connect()
const { user_id } = input

const workspace = await ctx.prisma.company.findFirst({
where: {
members: {
has: user_id,
},
},
})

return workspace
} finally {
await prisma.$disconnect()
}
}),
})
export const workspaceRouter = createTRPCRouter({
getWorkspace: publicProcedure
.input(
z.object({
user_id: z.string(),
}),
)
.query(async ({ input, ctx }) => {
const prisma = new PrismaClient()
try {
await prisma.$connect()
const { user_id } = input

const workspace = await ctx.prisma.company.findFirst({
where: {
members: {
has: user_id,
},
},
})

return workspace
} finally {
await prisma.$disconnect()
}
}),
})
but on my /pages/today.tsx where i need that workspace info, it's throwing Unhandled Runtime Error Error: Rendered more hooks than during the previous render
import { type NextPage } from 'next'
import { api } from '~/utils/api'
import { DateTime } from 'luxon'
import { useEffect, useState } from 'react'
const Today: NextPage = () => {
const [user, setUser] = useState<User>()
useEffect(() => {
const getUser = async () => {
const {
data: { session },
} = await supabase.auth.getSession()

if (!session) {
console.log('no session')
} else if (!session.user) {
console.log('no user')
} else {
console.log('session.user: ', session.user)
setUser(session.user)
}
}
void getUser()
}, [])

if (typeof user !== 'undefined') {
const temp_workspace = api.workspace.getWorkspace.useQuery({
user_id: user.id,
})
console.log('temp: ', temp_workspace)
}
}

export default Today
import { type NextPage } from 'next'
import { api } from '~/utils/api'
import { DateTime } from 'luxon'
import { useEffect, useState } from 'react'
const Today: NextPage = () => {
const [user, setUser] = useState<User>()
useEffect(() => {
const getUser = async () => {
const {
data: { session },
} = await supabase.auth.getSession()

if (!session) {
console.log('no session')
} else if (!session.user) {
console.log('no user')
} else {
console.log('session.user: ', session.user)
setUser(session.user)
}
}
void getUser()
}, [])

if (typeof user !== 'undefined') {
const temp_workspace = api.workspace.getWorkspace.useQuery({
user_id: user.id,
})
console.log('temp: ', temp_workspace)
}
}

export default Today
34 replies