nimeshvaghasiya
nimeshvaghasiya
Explore posts from servers
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 5/13/2023 in #questions
create-t3-turbo monorepo: How to access user session to packages/db?
I would like to access some props from user's session to prisma middleware i.e. in below example: I would like to get contextLanguage from user's session (nextauth). adding @acme/auth as a dependency to @acme/db package, may create circular dependency? https://www.prisma.io/docs/concepts/components/prisma-client/middleware/session-data-middleware
const prisma = new PrismaClient()

const contextLanguage = 'en-us' // Session state

prisma.$use(async (params, next) => {
if (params.model == 'Post' && params.action == 'create') {
params.args.data.language = contextLanguage
}

return next(params)
})

const create = await prisma.post.create({
data: {
title: 'My post in English',
},
})
const prisma = new PrismaClient()

const contextLanguage = 'en-us' // Session state

prisma.$use(async (params, next) => {
if (params.model == 'Post' && params.action == 'create') {
params.args.data.language = contextLanguage
}

return next(params)
})

const create = await prisma.post.create({
data: {
title: 'My post in English',
},
})
1 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 1/16/2023 in #questions
error - ReferenceError: Cannot access 'createTRPCRouter' before initialization
Anyone ever experience an error as in title of this Q. src\server\api\root.ts
import { createTRPCRouter } from "./trpc";
import { exampleRouter } from "./routers/example";
import { roleRouter } from "./routers/role";
export const appRouter = createTRPCRouter({
example: exampleRouter,
role: roleRouter,
.....
})
import { createTRPCRouter } from "./trpc";
import { exampleRouter } from "./routers/example";
import { roleRouter } from "./routers/role";
export const appRouter = createTRPCRouter({
example: exampleRouter,
role: roleRouter,
.....
})
If you change import order and move roleRouter import at top, it will throw error at roleRouter in below error description. Error Description:
{"props":{"pageProps":{"statusCode":500}},"page":"/_error","query":{"__NEXT_PAGE":"/api/trpc/auth.getSecretMessage,auth.getAllPermissions"},"buildId":"development","isFallback":false,"err":{"name":"ReferenceError","source":"server","message":"Cannot access 'createTRPCRouter' before initialization","stack":"ReferenceError: Cannot access 'createTRPCRouter' before initialization\n at Module.createTRPCRouter (webpack-internal:///(api)/./src/server/api/trpc.ts:5:65)\n at eval (webpack-internal:///(api)/./src/server/api/routers/example.ts:12:61)"},"gip":true,"locales":["en"],"scriptLoader":[]}
{"props":{"pageProps":{"statusCode":500}},"page":"/_error","query":{"__NEXT_PAGE":"/api/trpc/auth.getSecretMessage,auth.getAllPermissions"},"buildId":"development","isFallback":false,"err":{"name":"ReferenceError","source":"server","message":"Cannot access 'createTRPCRouter' before initialization","stack":"ReferenceError: Cannot access 'createTRPCRouter' before initialization\n at Module.createTRPCRouter (webpack-internal:///(api)/./src/server/api/trpc.ts:5:65)\n at eval (webpack-internal:///(api)/./src/server/api/routers/example.ts:12:61)"},"gip":true,"locales":["en"],"scriptLoader":[]}
20 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 12/13/2022 in #questions
Should you share zod schema from server side to client side?
I have a zod schema which is used to validate trpc router procedure on server, and I need same schema to validate input on client side form, so, is there any security threat, if I import that server schema on client component?
9 replies
TTCTheo's Typesafe Cult
Created by nimeshvaghasiya on 11/10/2022 in #questions
Next 13 - App Directory feature and tRPC
Is there any pre-release version of create-t3-app which has been updated to App Directory feature and also updated tRPC accordingly?
15 replies