traches
traches
TTCTheo's Typesafe Cult
Created by traches on 2/11/2025 in #questions
Next-auth Session is null on initial render with useSuspenseQuery
This one's been driving me crazy and I would love some help. I can't even work out whether it's TRPC, react query, or next-auth that's causing the issue. I'm using TRPC 11.0.0-rc-682, next-auth 5.0.0-beta.25, and the nextjs 15.1.3 app router. I have a route with an id param:
// src/app/artefacts/[artefactId]/page.tsx
// imports

function Page({ routeParams }: InferPagePropsType<RouteType>) {
const [{ artefactId }, session] = use(Promise.all([routeParams, auth()]))

void trpc.artefacts.getById.prefetch({ artefactId })

return (
<MainContainer>
<ArtefactView artefactId={artefactId} />
</MainContainer>
)
}

export default withParamValidation(Page, Route)
// src/app/artefacts/[artefactId]/page.tsx
// imports

function Page({ routeParams }: InferPagePropsType<RouteType>) {
const [{ artefactId }, session] = use(Promise.all([routeParams, auth()]))

void trpc.artefacts.getById.prefetch({ artefactId })

return (
<MainContainer>
<ArtefactView artefactId={artefactId} />
</MainContainer>
)
}

export default withParamValidation(Page, Route)
ArtefactView is a client component with a useSuspenseQuery:
'use client'

import { useSession } from 'next-auth/react'

import { api } from '~/trpc/client'
import { type ArtefactID } from '~/types'

export const ArtefactView: React.FC<{
artefactId: ArtefactID
}> = ({ artefactId }) => {
const session = useSession().data

const [artefact] = api.artefacts.getById.useSuspenseQuery({ artefactId })

// render
}
'use client'

import { useSession } from 'next-auth/react'

import { api } from '~/trpc/client'
import { type ArtefactID } from '~/types'

export const ArtefactView: React.FC<{
artefactId: ArtefactID
}> = ({ artefactId }) => {
const session = useSession().data

const [artefact] = api.artefacts.getById.useSuspenseQuery({ artefactId })

// render
}
artefacts.getById is protected by middleware that checks for a session and throws an unauthorized error if missing. Navigating to this page from another page works fine, but if I perform a hard refresh I get an unauthorized error and a fall-back to client rendering. I've traced the cause down to the session being null in my protectedProcedure, but only on the initial SSR pass. I'm sure I've messed up the setup code somewhere, but I'm not sure where to look? Any advice is greatly appreciated. I wanted to paste more code here but the character limit won't let me.
5 replies
TTCTheo's Typesafe Cult
Created by traches on 1/17/2025 in #questions
Is it safe to ignore occasional next-auth CLIENT_FETCH_ERROR reports if everything seems fine?
I'm running t3 app with ~100 users on vercel using Next-auth, and I'm getting these errors in sentry. I'm fairly certain these are happening because of network issues on the client that I really don't have any control over, but I'm not sure how to ensure that's the case? Is there a way I can configure next-auth to handle these more gracefully? Error message: [next-auth][error][CLIENT_FETCH_ERROR] https://next-auth.js.org/errors#client_fetch_error Failed to fetch [object Object]
2 replies
TTCTheo's Typesafe Cult
Created by traches on 10/20/2023 in #questions
Drizzle & Planetscale data migration workflow
Tagged as "databases" because there's no Drizzle tag. I'm running T3 + Drizzle + Planetscale. I've been using a planetscale branch -> db:push -> deploy request workflow for managing schema changes, which I like a lot. This doesn't handle modifications to existing data however, so I still need a way to run a set of SQL commands against an existing database exactly once. Drizzle-kit claims to be able to do this with drizzle-kit generate:mysql --custom, but this doesn't generate an empty SQL file for me like the docs say it will. On first run it creates all the tables in my schema, and subsequently it says there aren't any changes to make and it does nothing. (In other words it seems to ignore the --custom flag). Do I have to implement this myself? Make a migrations table, track which migrations have been run, call the ones that haven't? Is there some other way? I can't be the only one with this issue.
7 replies