entropy
entropy
Explore posts from servers
DTDrizzle Team
Created by entropy on 10/11/2024 in #help
Drizzle kit push and migrate don't match typescript schema
No description
9 replies
TtRPC
Created by entropy on 9/6/2023 in #❓-help
getting the progress of a trpc query
Hello, I want to be able to stream the progress of a trpc client query call, so I can link it to a progress bar in the ui. Is this possible?
2 replies
DIAdiscord.js - Imagine an app
Created by entropy on 9/5/2023 in #djs-questions
Global commands push cause dev/local commands guild to have duplicates
Hello, I'm currently trying to setup a system where in development I run local commands, but for production I global deploy. The problem is that my dev/local commands guild ends up with duplicates of each command. I read in the discord documentation that the put route should overwrite any commands with the same name, but this seems to only apply within each scope. So if do local deploy it overwrites, but if I then global push it creates new ones within the dev/local guild. If anyone has a solution to this it would be much appreciated! deployCommands.ts: https://codefile.io/f/InFuvMpf1h
8 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
I'm currently trying to add Clerk auth to my trpc context, but I just keep getting this error: Error: Unexpected token '<', "<!DOCTYPE "... is not valid JSON This is my code: context.ts
import { NextRequest } from 'next/server'
import { getAuth } from '@clerk/nextjs/server'
import { FetchCreateContextFnOptions } from '@trpc/server/adapters/fetch'

export function createContext(opts: FetchCreateContextFnOptions) {
const auth = getAuth(opts.req as NextRequest)

return {
auth,
headers: opts && Object.fromEntries(opts.req.headers)
}
}

export type Context = Awaited<ReturnType<typeof createContext>>
import { NextRequest } from 'next/server'
import { getAuth } from '@clerk/nextjs/server'
import { FetchCreateContextFnOptions } from '@trpc/server/adapters/fetch'

export function createContext(opts: FetchCreateContextFnOptions) {
const auth = getAuth(opts.req as NextRequest)

return {
auth,
headers: opts && Object.fromEntries(opts.req.headers)
}
}

export type Context = Awaited<ReturnType<typeof createContext>>
trpc.ts
import { TRPCError, initTRPC } from '@trpc/server'
import superjson from 'superjson'
import { ZodError } from 'zod'

import { Context } from './context'

const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter(opts) {
const { shape, error } = opts
return {
...shape,
data: {
...shape.data,
zodError:
error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
? error.cause.flatten()
: null
}
}
}
})

const isAuthed = t.middleware(({ next, ctx }) => {
console.log('isAuthed', ctx.auth)

if (!ctx.auth.userId) {
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Not authenticated' })
}
return next({
ctx: {
auth: ctx.auth
}
})
})

export const router = t.router
export const publicProcedure = t.procedure
export const protectedProcedure = t.procedure.use(isAuthed)
import { TRPCError, initTRPC } from '@trpc/server'
import superjson from 'superjson'
import { ZodError } from 'zod'

import { Context } from './context'

const t = initTRPC.context<Context>().create({
transformer: superjson,
errorFormatter(opts) {
const { shape, error } = opts
return {
...shape,
data: {
...shape.data,
zodError:
error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
? error.cause.flatten()
: null
}
}
}
})

const isAuthed = t.middleware(({ next, ctx }) => {
console.log('isAuthed', ctx.auth)

if (!ctx.auth.userId) {
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Not authenticated' })
}
return next({
ctx: {
auth: ctx.auth
}
})
})

export const router = t.router
export const publicProcedure = t.procedure
export const protectedProcedure = t.procedure.use(isAuthed)
53 replies