mrnicericee
mrnicericee
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Nemila on 5/15/2023 in #questions
Your experience with T3 for Mobile dev
I would say, try it out 🙂 it works well imo here's the starter repo https://github.com/t3-oss/create-t3-turbo
3 replies
TTCTheo's Typesafe Cult
Created by headadmiral on 5/15/2023 in #questions
Does it make sense to use tRPC without a frontend?
not necessarily, if you like the DX of trpc backend to creating the routes & procedures & testing. It makes sense to use the trpc server still. you can even just go with next, express, fastify or node
5 replies
TTCTheo's Typesafe Cult
Created by janusqa on 5/12/2023 in #questions
Is it possible to pass a zod schema as a prop?
8 replies
TTCTheo's Typesafe Cult
Created by l on 4/28/2023 in #questions
InfiniteQuery or Pagination
Hey luka! with drizzle you have to write the query closer to sql. the infinite query is weirdly placed in the title because it's mostly a frontend abstraction of the backend pagination. so, it sounds like you want to learn more about different ways to paginate data in the backend! since it would be terrible to receive thousands of rows of data! the one that will be the easiest to implement is limit + offset. pros: able to do pages, and you can do "page 1" and go to "page 200" very easily. cons: say you are paginating 25 at a time, and you want to query row 1 million, the select has to iterate 1 million times + fetch your 25. the one i typically use is key set. you have a column & id you agree on that you will do a WHERE statement on pros: fetching the million + 25, now is a lot faster because it skipped all of the first million, and goes for the 25. cons: can't do "page 1" to page "200", since you need the cursor/key set id what i mentioned just now is described in great detail by slack. i recommend giving it a read, and then looking up how to do both limit + offset and key set paginations. you're most likely be fine with just a limit + offset solution 🙂 https://slack.engineering/evolving-api-pagination-at-slack/
3 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
it could get reduced to that
34 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
import { type NextPage } from 'next'
import { api } from '~/utils/api'
import { DateTime } from 'luxon'
import { useUser } from '@supabase/auth-helpers-react'
import { useEffect, useState } from 'react'
const Today: NextPage = () => {
const user = useUser() // use the supabase hook to check if there is a user
const temp_workspace = api.workspace.getWorkspace.useQuery({
user_id: user.id,
}, {
enabled: !!user, // won't run unless there is a user
})
}

export default Today
import { type NextPage } from 'next'
import { api } from '~/utils/api'
import { DateTime } from 'luxon'
import { useUser } from '@supabase/auth-helpers-react'
import { useEffect, useState } from 'react'
const Today: NextPage = () => {
const user = useUser() // use the supabase hook to check if there is a user
const temp_workspace = api.workspace.getWorkspace.useQuery({
user_id: user.id,
}, {
enabled: !!user, // won't run unless there is a user
})
}

export default Today
34 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
from the docs it looks like you're trying to redo the supabase useUser hook? source: https://supabase.com/docs/guides/auth/auth-helpers/nextjs
import { Auth } from '@supabase/auth-ui-react'
import { ThemeSupa } from '@supabase/auth-ui-shared'
import { useUser, useSupabaseClient } from '@supabase/auth-helpers-react'
import { useEffect, useState } from 'react'

const LoginPage = () => {
const supabaseClient = useSupabaseClient()
const user = useUser()
const [data, setData] = useState()

useEffect(() => {
async function loadData() {
const { data } = await supabaseClient.from('test').select('*')
setData(data)
}
// Only run query once user is logged in.
if (user) loadData()
}, [user])

if (!user)
return (
<Auth
redirectTo="http://localhost:3000/"
appearance={{ theme: ThemeSupa }}
supabaseClient={supabaseClient}
providers={['google', 'github']}
socialLayout="horizontal"
/>
)

return (
<>
<button onClick={() => supabaseClient.auth.signOut()}>Sign out</button>
<p>user:</p>
<pre>{JSON.stringify(user, null, 2)}</pre>
<p>client-side data fetching with RLS</p>
<pre>{JSON.stringify(data, null, 2)}</pre>
</>
)
}

export default LoginPage
import { Auth } from '@supabase/auth-ui-react'
import { ThemeSupa } from '@supabase/auth-ui-shared'
import { useUser, useSupabaseClient } from '@supabase/auth-helpers-react'
import { useEffect, useState } from 'react'

const LoginPage = () => {
const supabaseClient = useSupabaseClient()
const user = useUser()
const [data, setData] = useState()

useEffect(() => {
async function loadData() {
const { data } = await supabaseClient.from('test').select('*')
setData(data)
}
// Only run query once user is logged in.
if (user) loadData()
}, [user])

if (!user)
return (
<Auth
redirectTo="http://localhost:3000/"
appearance={{ theme: ThemeSupa }}
supabaseClient={supabaseClient}
providers={['google', 'github']}
socialLayout="horizontal"
/>
)

return (
<>
<button onClick={() => supabaseClient.auth.signOut()}>Sign out</button>
<p>user:</p>
<pre>{JSON.stringify(user, null, 2)}</pre>
<p>client-side data fetching with RLS</p>
<pre>{JSON.stringify(data, null, 2)}</pre>
</>
)
}

export default LoginPage
34 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
the useEffect probably is the one that's running too many times
34 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
you're also using a useEffect remove getUser from the useEffect, and if you really want to, put it on a useCallBack
34 replies
TTCTheo's Typesafe Cult
Created by Maïeul on 3/17/2023 in #questions
Auth: which solution for which situation
it is, and tbh I still recommend at least trying to build out your own auth when starting out (or want to know how auth solutions work). You learn best when things aren't working think plus you get to understand authorization vs authentication
21 replies
TTCTheo's Typesafe Cult
Created by Maïeul on 3/17/2023 in #questions
Auth: which solution for which situation
btw, if you haven't already make this into an article write it up! 🙂
21 replies
TTCTheo's Typesafe Cult
Created by Maïeul on 3/17/2023 in #questions
Auth: which solution for which situation
This is a great summary of each solution! Love how you mentioned each pros and cons. rolling your own auth is great for getting started (as a developer and/or in a project). IMO, i'd rather hand over auth to someone else. I can focus on what I need/want to do, and auth becomes the easiest thing to implement, plus because auth is their business, they'll either 1. already have what features you need when you need them, or 2. already working on building it out.
21 replies
TTCTheo's Typesafe Cult
Created by feldrok on 3/15/2023 in #questions
tRPC API endpoints?
also quick note, POST probably should be a mutation instead of a query, since it's mutating something on the server
16 replies
TTCTheo's Typesafe Cult
Created by feldrok on 3/15/2023 in #questions
tRPC API endpoints?
open-api trpc requires you to do an output iirc, it's also used to generate the open-api docs 🙂
16 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/15/2023 in #questions
Prisma Docs not working as instructed for insensitive case search. 9am and my brain hurts.
your original has was really close looks like
18 replies
TTCTheo's Typesafe Cult
Created by Debaucus on 3/15/2023 in #questions
Prisma Docs not working as instructed for insensitive case search. 9am and my brain hurts.
18 replies